From 5f2bc4da498d71d71b11fe1fa0a889eb6ed7f259 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sun, 30 Jul 2017 22:37:51 +0100 Subject: [PATCH] Added the logging endpoint at /api/v1/Logging for the UI logs #1465 --- CHANGELOG.md | 2 + src/Ombi/Controllers/LoggingController.cs | 50 +++++++++++++++++++++++ src/Ombi/Models/UiLoggingModel.cs | 15 +++++++ 3 files changed, 67 insertions(+) create mode 100644 src/Ombi/Controllers/LoggingController.cs create mode 100644 src/Ombi/Models/UiLoggingModel.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index d18c137ad..baa067dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/src/Ombi/Controllers/LoggingController.cs b/src/Ombi/Controllers/LoggingController.cs new file mode 100644 index 000000000..83a6b5ad9 --- /dev/null +++ b/src/Ombi/Controllers/LoggingController.cs @@ -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; + } + } + } +} diff --git a/src/Ombi/Models/UiLoggingModel.cs b/src/Ombi/Models/UiLoggingModel.cs new file mode 100644 index 000000000..1a352ef02 --- /dev/null +++ b/src/Ombi/Models/UiLoggingModel.cs @@ -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; } + } +}