Created
December 14, 2017 17:38
-
-
Save stephenpatten/efbd52d7fb9ebda9113310a776f9c88d to your computer and use it in GitHub Desktop.
SerilogBootstrapV6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static ILogger ConfigureLogger() | |
| { | |
| // By sharing between the Seq sink and logger itself, | |
| // Seq API keys can be used to control the level of the whole logging pipeline. | |
| var levelSwitch = new LoggingLevelSwitch(); | |
| var appSettings = ConfigurationManager.AppSettings; | |
| var filePath = | |
| $"{ConfigurationManager.AppSettings["serilog:Log:FilePath"]}\\DocumentReceiver_{Environment.MachineName}_.txt"; | |
| const string workflowSerilogV6 = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}|{Level:u3}|{CorrelationId}|{MachineName}|{Application}|{ProcessId}|{ThreadId}|{SourceContext:l}|{Message}|{NewLine}{Exception}"; | |
| return Log.Logger = new LoggerConfiguration() | |
| .MinimumLevel.ControlledBy(levelSwitch) | |
| .Enrich.FromLogContext() | |
| .Enrich.WithMachineName() | |
| .Enrich.WithProcessId() | |
| .Enrich.WithThreadId() | |
| .Enrich.WithProperty("Application", "xxx") | |
| .WriteTo.Seq(appSettings["serilog:write-to:Seq.serverUrl"], | |
| apiKey: appSettings["serilog:write-to:Seq.apiKey"], | |
| compact: true) | |
| .WriteTo.Async(a => | |
| a.File(filePath, | |
| outputTemplate: workflowSerilogV6, | |
| retainedFileCountLimit: 31, | |
| rollingInterval: RollingInterval.Day, | |
| rollOnFileSizeLimit: true, | |
| buffered: true, | |
| flushToDiskInterval: TimeSpan.FromMilliseconds(500))) | |
| .CreateLogger(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment