using System; using LCU.API.Collections.RepoApi.Configuration; using LCU.Shared.Collections.RepoApiLib.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.FeatureManagement.Mvc; using Serilog; namespace LCU.API.Collections.RepoApi.Controllers { [Route("api/[controller]")] [ApiController] [FeatureGate(FeatureFlags.EnableControllers)] public class LoggingController : RepoControllerBase { public LoggingController(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor) { } /// /// Use to send something to the logger from the client /// /// /// Logs a message from a client. /// Cookies: None required or set. /// Security: Must have a valid JWT token retrieved from Azure AD, with ADMIN role. /// // Post: api/Logging/Error [HttpPost("Error")] [ProducesResponseType(200)] [ProducesResponseType(400)] [ProducesResponseType(403)] [ProducesResponseType(500)] public IActionResult Post([FromBody] ClientError error) { try { Log.Error($"Client Exception: <{ error.Name}> : {error.Message} => {error.StackTrace}"); return Ok(); } catch (Exception e) { Log.Fatal(e,"Failed to log client error. Exception Thrown."); return StatusCode((int) System.Net.HttpStatusCode.InternalServerError); } } } }