-
Notifications
You must be signed in to change notification settings - Fork 18
/
Program.cs
46 lines (42 loc) · 1.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Modified by Splunk Inc.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Formatting.Json;
namespace MicrosoftExtensionsExample
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddHostedService<Worker>())
.ConfigureLogging(logging =>
{
// The JsonFormatter used by NetEscapades.Extensions.Logging.RollingFile includes all properties
// if scopes are enabled
//
// Additions to configuration:
// - used json format
// - enabled scopes
logging.AddFile(opts =>
{
opts.IncludeScopes = true; // must include scopes so that correlation identifiers are added
opts.FileName = "log-MicrosoftExtensions-jsonFile";
opts.Extension = "log";
opts.FormatterName = "json";
});
// Using Serilog with Microsoft.Extensions.Logging is supported, but uses the Serilog log injection
// not Microsoft.Extensions.Logging logs injection.
// See the SerilogExample project for examples of valid Serilog configurations and output formats
logging.AddSerilog(new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.File(new JsonFormatter(), "Logs/log-Serilog-jsonFile.log")
.CreateLogger());
});
}
}