Updated EllieBot.Coordinator
This commit is contained in:
parent
960f6f093c
commit
c69f7951a7
18 changed files with 993 additions and 2 deletions
src/EllieBot.Coordinator
43
src/EllieBot.Coordinator/LogSetup.cs
Normal file
43
src/EllieBot.Coordinator/LogSetup.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Serilog.Sinks.SystemConsole.Themes;
|
||||
|
||||
namespace EllieBot.Services
|
||||
{
|
||||
public static class LogSetup
|
||||
{
|
||||
public static void SetupLogger(object source)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("System", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File("coord.log", LogEventLevel.Information,
|
||||
rollOnFileSizeLimit: true,
|
||||
fileSizeLimitBytes: 10_000_000)
|
||||
.WriteTo.Console(LogEventLevel.Information,
|
||||
theme: GetTheme(),
|
||||
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] | #{LogSource} | {Message:lj}{NewLine}{Exception}")
|
||||
.Enrich.WithProperty("LogSource", source)
|
||||
.CreateLogger();
|
||||
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
private static ConsoleTheme GetTheme()
|
||||
{
|
||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
return AnsiConsoleTheme.Code;
|
||||
|
||||
|
||||
#if DEBUG
|
||||
return AnsiConsoleTheme.Code;
|
||||
#else
|
||||
return ConsoleTheme.None;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue