Skip to content

Instantly share code, notes, and snippets.

@lettucebo
Last active April 30, 2019 03:18
Show Gist options
  • Save lettucebo/111a9d2d5a78eba2eb5ea5e8c786b18d to your computer and use it in GitHub Desktop.
Save lettucebo/111a9d2d5a78eba2eb5ea5e8c786b18d to your computer and use it in GitHub Desktop.
// 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