Added the logging endpoint at /api/v1/Logging for the UI logs #1465

pull/1488/head
tidusjar 8 years ago
parent 22aca7d2fd
commit 5f2bc4da49

@ -84,6 +84,8 @@
### **Fixes**
- Fixed the Identity Server discovery bug #1456 #865. [tidusjar]
- Fixed the issue with the Identity Server running on a different port, we can now use -url #865. [Jamie.Rees]
- Try again. [TidusJar]

@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Ombi.Models;
using System;
namespace Ombi.Controllers
{
[Authorize]
public class LoggingController : BaseV1ApiController
{
public LoggingController(ILogger logger)
{
Logger = logger;
}
private ILogger Logger { get; }
[HttpPost]
public void Log([FromBody]UiLoggingModel l)
{
l.DateTime = DateTime.UtcNow;
var exception = new Exception(l.Description, new Exception(l.StackTrace));
switch (l.Level)
{
case LogLevel.Trace:
Logger.LogTrace(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.Debug:
Logger.LogDebug(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.Information:
Logger.LogInformation(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.Warning:
Logger.LogWarning(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.Error:
Logger.LogError(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.Critical:
Logger.LogCritical(new EventId(l.Id), "Exception: {0} at {1}. Stacktrade {2}", l.Description, l.Location, l.StackTrace);
break;
case LogLevel.None:
break;
}
}
}
}

@ -0,0 +1,15 @@
using Microsoft.Extensions.Logging;
using System;
namespace Ombi.Models
{
public class UiLoggingModel
{
public LogLevel Level { get; set; }
public string Description { get; set; }
public int Id { get; set; }
public string Location { get; set; }
public string StackTrace { get; set; }
public DateTime DateTime { get; set; }
}
}
Loading…
Cancel
Save