-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
SerilogConfigurator.cs
27 lines (25 loc) · 1003 Bytes
/
SerilogConfigurator.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
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Logging;
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Core;
namespace HappyCode.NetCoreBoilerplate.Api.Infrastructure.Configurations
{
public static class SerilogConfigurator
{
public static Logger CreateLogger()
{
var configuration = LoadAppConfiguration();
return new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.With(new VersionEnricher(new ()))
.CreateLogger();
}
private static IConfigurationRoot LoadAppConfiguration()
{
return new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
.Build();
}
}
}