Created
April 30, 2019 03:15
-
-
Save lettucebo/e527be5b184ef3e89eea95708597cff1 to your computer and use it in GitHub Desktop.
This file contains 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
// init logger | |
DevelopLogger developLogger = new DevelopLogger(new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.Enrich.WithMachineName() | |
.Enrich.FromLogContext() | |
.WriteTo.Console() | |
.CreateLogger()); | |
UserLogger userLogger = new UserLogger(new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.Enrich.WithMachineName() | |
.Enrich.FromLogContext() | |
.WriteTo.Console() | |
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200")) | |
{ | |
MinimumLogEventLevel = LogEventLevel.Information, | |
AutoRegisterTemplate = true, | |
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, | |
IndexFormat = "console-index2-{0:yyyy.MM}", | |
FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate) | |
}) | |
.CreateLogger()); | |
// start log, this will be using dependency injection | |
developLogger.Log.Warning("{random} Serilog Example: {now}", random.Next(300, 500), | |
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")); | |
userLogger.Log.Error(new NotImplementedException("yoyoyo"), "{random} Serilog Example: {now}", | |
random.Next(300, 500), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment