Last active
April 30, 2019 03:18
-
-
Save lettucebo/111a9d2d5a78eba2eb5ea5e8c786b18d 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 | |
WsSerilog.UserLog = 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(); | |
WsSerilog.DevelopLog = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.Enrich.WithMachineName() | |
.Enrich.FromLogContext() | |
.Enrich.WithProperty("Environment", "Dev") | |
.WriteTo.Console() | |
.CreateLogger(); | |
// start log, using static way | |
WsSerilog.DevelopLog.Warning("{random} Serilog Example: {now}", random.Next(300, 500), | |
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")); | |
WsSerilog.UserLog.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