24 lines
828 B
C#
Executable File
24 lines
828 B
C#
Executable File
using Opsoft.NetCore.O3App.Shared;
|
|
using Serilog.Events;
|
|
using System.IO;
|
|
|
|
namespace Opsoft.NetCore.O3App.Infrastructure
|
|
{
|
|
public class SkynetLoggerFormatter : Serilog.Formatting.ITextFormatter
|
|
{
|
|
public void Format(LogEvent logEvent, TextWriter output)
|
|
{
|
|
output.WriteLine($"{logEvent.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff")} {GetSkynetLevel(logEvent.Level)} {logEvent.MessageTemplate.Render(logEvent.Properties)}");
|
|
if (logEvent.Exception != null)
|
|
{
|
|
output.WriteLine(logEvent.Exception);
|
|
}
|
|
}
|
|
|
|
private static string GetSkynetLevel(LogEventLevel level)
|
|
{
|
|
return level == LogEventLevel.Information || level == LogEventLevel.Warning ? level.ToString().Left(4) : level.ToString();
|
|
}
|
|
}
|
|
}
|