using Church.Net.Entity; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Threading.Tasks; using WebAPI.Logics.Interface; using WebAPI.Services.Interfaces; namespace WebAPI.Controllers { [Route("[controller]/[action]")] [ApiController] public class LogController : ApiControllerBase { private readonly ILoggingService loggingService; public LogController( ICrudLogic logic, ILoggingService loggingService ) : base(logic) { this.loggingService = loggingService; } [HttpPost] public void PurgeBefore([FromBody] DateTime date) { logic.Delete(l => l.Time <= date.ToUniversalTime()); } [Route("/error-development")] public IActionResult HandleErrorDevelopment( [FromServices] IHostEnvironment hostEnvironment) { if (!hostEnvironment.IsDevelopment()) { return NotFound(); } var exceptionHandlerFeature = HttpContext.Features.Get()!; this.loggingService.Error(exceptionHandlerFeature.Error, exceptionHandlerFeature.Path); return Problem( detail: exceptionHandlerFeature.Error.StackTrace, title: exceptionHandlerFeature.Error.Message); } [Route("/error")] public IActionResult HandleError() { var exceptionHandlerFeature = HttpContext.Features.Get()!; this.loggingService.Error(exceptionHandlerFeature.Error, exceptionHandlerFeature.Path); return Problem(); } } }