-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
54 lines (47 loc) · 1.96 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
47
48
49
50
51
52
53
54
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Events;
namespace SerilogLogging
{
public class Program
{
public static void Main(string[] args)
{
//CreateFileLogger();
CreateFileLoggerUsingJSONFile();
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog()
.Build();
public static void CreateFileLogger()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("SerilogDemo", LogEventLevel.Information)
.WriteTo.File("Logs/Example.txt",
LogEventLevel.Information, // Minimum Log level
rollingInterval: RollingInterval.Day, // This will append time period to the filename like Example20180316.txt
retainedFileCountLimit: null,
fileSizeLimitBytes: null,
outputTemplate: "{Timestamp:dd-MMM-yyyy HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", // Set custom file format
shared: true // Shared between multi-process shared log files
)
.CreateLogger();
}
private static void CreateFileLoggerUsingJSONFile()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
}
}
}