Files
2026-04-20 14:47:24 -05:00

48 lines
1.6 KiB
C#

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)
{
}
/// <summary>
/// Use to send something to the logger from the client
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
// 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);
}
}
}
}