-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
26 lines (18 loc) · 849 Bytes
/
Program.cs
File metadata and controls
26 lines (18 loc) · 849 Bytes
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
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Json;
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
// Create the actual logger
.CreateLogger();
logger.ForContext<Program>().Information("Hello World");
logger.ForContext(Constants.SourceContextPropertyName, "TWC").Warning("Hola, I'm a Warning!");
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello. This is Microsoft greeting!");
Log.CloseAndFlush();