File tree Expand file tree Collapse file tree 7 files changed +44
-1
lines changed Expand file tree Collapse file tree 7 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1616 <PackageReference Include =" Serilog" />
1717 <PackageReference Include =" Serilog.Exceptions" />
1818 <PackageReference Include =" Serilog.Extensions.Hosting" />
19+ <PackageReference Include =" Serilog.Formatting.Compact" />
1920 <PackageReference Include =" Serilog.Settings.Configuration" />
2021 <PackageReference Include =" Serilog.Sinks.ApplicationInsights" />
2122 <PackageReference Include =" Serilog.Sinks.Async" />
Original file line number Diff line number Diff line change 66using Microsoft . ApplicationInsights . Extensibility ;
77using Serilog ;
88using Serilog . Exceptions ;
9+ using Serilog . Formatting ;
10+ using Serilog . Formatting . Compact ;
11+ using Serilog . Formatting . Display ;
912
1013DotNetEnv . Env . TraversePath ( ) . Load ( ) ;
1114
3942
4043 builder . Host . UseSerilog ( ( ctx , services , loggerConfig ) =>
4144 {
45+ ITextFormatter formatter = new MessageTemplateTextFormatter ( outputTemplate : logFormat , formatProvider : CultureInfo . InvariantCulture ) ;
46+
47+ if ( EnvVarAccessors . UseJsonFormatting )
48+ {
49+ formatter = new CompactJsonFormatter ( ) ;
50+ }
51+
4252 loggerConfig
4353 . ReadFrom . Configuration ( ctx . Configuration )
4454 . Enrich . FromLogContext ( )
4555 . Enrich . WithExceptionDetails ( )
46- . WriteTo . Async ( x => x . Console ( outputTemplate : logFormat , formatProvider : CultureInfo . InvariantCulture ) ) ;
56+ . WriteTo . Async ( x => x . Console ( formatter ) ) ;
4757
4858 if ( ctx . HostingEnvironment . IsProduction ( ) )
4959 {
Original file line number Diff line number Diff line change 130130 "Serilog.Extensions.Logging" : " 9.0.0"
131131 }
132132 },
133+ "Serilog.Formatting.Compact" : {
134+ "type" : " Direct" ,
135+ "requested" : " [3.0.0, )" ,
136+ "resolved" : " 3.0.0" ,
137+ "contentHash" : " wQsv14w9cqlfB5FX2MZpNsTawckN4a8dryuNGbebB/3Nh1pXnROHZov3swtu3Nj5oNG7Ba+xdu7Et/ulAUPanQ==" ,
138+ "dependencies" : {
139+ "Serilog" : " 4.0.0"
140+ }
141+ },
133142 "Serilog.Settings.Configuration" : {
134143 "type" : " Direct" ,
135144 "requested" : " [9.0.0, )" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ namespace Common;
33public static class EnvVarKeys
44{
55 public const string KeyVaultName = "KEY_VAULT_NAME" ;
6+ public const string UseJsonFormatting = "USE_JSON_FORMATTING" ;
67 public const string UseOutputCache = "USE_OUTPUT_CACHE" ;
78 public const string MarketClientUrl = "MARKET_CLIENT_URL" ;
89 public const string UseMocking = "USE_MOCKING" ;
@@ -12,4 +13,7 @@ public static class EnvVarAccessors
1213{
1314 public static bool UseMocking =>
1415 bool . TryParse ( Environment . GetEnvironmentVariable ( EnvVarKeys . UseMocking ) , out var value ) && value ;
16+
17+ public static bool UseJsonFormatting =>
18+ bool . TryParse ( Environment . GetEnvironmentVariable ( EnvVarKeys . UseJsonFormatting ) , out var value ) && value ;
1519}
Original file line number Diff line number Diff line change 1919 <PackageVersion Include =" Serilog" Version =" 4.3.0" />
2020 <PackageVersion Include =" Serilog.Exceptions" Version =" 8.4.0" />
2121 <PackageVersion Include =" Serilog.Extensions.Hosting" Version =" 9.0.0" />
22+ <PackageVersion Include =" Serilog.Formatting.Compact" Version =" 3.0.0" />
2223 <PackageVersion Include =" Serilog.Settings.Configuration" Version =" 9.0.0" />
2324 <PackageVersion Include =" Serilog.Sinks.ApplicationInsights" Version =" 4.0.0" />
2425 <PackageVersion Include =" Serilog.Sinks.Async" Version =" 2.1.0" />
Original file line number Diff line number Diff line change 852852 "Serilog" : " 4.2.0"
853853 }
854854 },
855+ "Serilog.Formatting.Compact" : {
856+ "type" : " Transitive" ,
857+ "resolved" : " 3.0.0" ,
858+ "contentHash" : " wQsv14w9cqlfB5FX2MZpNsTawckN4a8dryuNGbebB/3Nh1pXnROHZov3swtu3Nj5oNG7Ba+xdu7Et/ulAUPanQ==" ,
859+ "dependencies" : {
860+ "Serilog" : " 4.0.0"
861+ }
862+ },
855863 "Serilog.Settings.Configuration" : {
856864 "type" : " Transitive" ,
857865 "resolved" : " 9.0.0" ,
17981806 "Serilog" : " [4.3.0, )" ,
17991807 "Serilog.Exceptions" : " [8.4.0, )" ,
18001808 "Serilog.Extensions.Hosting" : " [9.0.0, )" ,
1809+ "Serilog.Formatting.Compact" : " [3.0.0, )" ,
18011810 "Serilog.Settings.Configuration" : " [9.0.0, )" ,
18021811 "Serilog.Sinks.ApplicationInsights" : " [4.0.0, )" ,
18031812 "Serilog.Sinks.Async" : " [2.1.0, )" ,
Original file line number Diff line number Diff line change 10431043 "Serilog" : " 4.2.0"
10441044 }
10451045 },
1046+ "Serilog.Formatting.Compact" : {
1047+ "type" : " Transitive" ,
1048+ "resolved" : " 3.0.0" ,
1049+ "contentHash" : " wQsv14w9cqlfB5FX2MZpNsTawckN4a8dryuNGbebB/3Nh1pXnROHZov3swtu3Nj5oNG7Ba+xdu7Et/ulAUPanQ==" ,
1050+ "dependencies" : {
1051+ "Serilog" : " 4.0.0"
1052+ }
1053+ },
10461054 "Serilog.Settings.Configuration" : {
10471055 "type" : " Transitive" ,
10481056 "resolved" : " 9.0.0" ,
20202028 "Serilog" : " [4.3.0, )" ,
20212029 "Serilog.Exceptions" : " [8.4.0, )" ,
20222030 "Serilog.Extensions.Hosting" : " [9.0.0, )" ,
2031+ "Serilog.Formatting.Compact" : " [3.0.0, )" ,
20232032 "Serilog.Settings.Configuration" : " [9.0.0, )" ,
20242033 "Serilog.Sinks.ApplicationInsights" : " [4.0.0, )" ,
20252034 "Serilog.Sinks.Async" : " [2.1.0, )" ,
You can’t perform that action at this time.
0 commit comments