7
7
using System . Text ;
8
8
using Serilog ;
9
9
using Serilog . Core ;
10
- using Serilog . Formatting ;
11
10
using Logger = NewRelic . Agent . Core . Logging . Logger ;
12
11
using NewRelic . Agent . Core . Logging ;
13
- using Serilog . Templates ;
14
12
using Serilog . Events ;
15
13
#if NETSTANDARD2_0
16
14
using System . Runtime . InteropServices ;
@@ -25,8 +23,9 @@ public static class LoggerBootstrapper
25
23
//private static ILayout AuditLogLayout = new PatternLayout("%utcdate{yyyy-MM-dd HH:mm:ss,fff} NewRelic %level: %message\r\n");
26
24
//private static ILayout FileLogLayout = new PatternLayout("%utcdate{yyyy-MM-dd HH:mm:ss,fff} NewRelic %6level: [pid: %property{pid}, tid: %property{threadid}] %message\r\n");
27
25
28
- private static ExpressionTemplate AuditLogLayout = new ExpressionTemplate ( "{UtcDateTime(@t):yyyy-MM-dd HH:mm:ss,fff} NewRelic Audit: {@m}\n " ) ;
29
- private static ExpressionTemplate FileLogLayout = new ExpressionTemplate ( "{UtcDateTime(@t):yyyy-MM-dd HH:mm:ss,fff} NewRelic {NRLogLevel,6}: [pid: {pid}, tid: {tid}] {@m}\n {@x}" ) ;
26
+ private const string AuditLogLayout = "{UTCTimestamp} NewRelic Audit: {Message:l}\n " ;
27
+
28
+ private const string FileLogLayout = "{UTCTimestamp} NewRelic {NRLogLevel,6}: [pid: {pid}, tid: {tid}] {Message:l}\n {Exception:l}" ;
30
29
31
30
private static LoggingLevelSwitch _loggingLevelSwitch = new LoggingLevelSwitch ( ) ;
32
31
@@ -40,7 +39,7 @@ public static void UpdateLoggingLevel(string newLogLevel)
40
39
public static void Initialize ( )
41
40
{
42
41
var startupLoggerConfig = new LoggerConfiguration ( )
43
- . Enrich . With ( new ThreadIdEnricher ( ) , new ProcessIdEnricher ( ) , new NrLogLevelEnricher ( ) )
42
+ . Enrich . With ( new ThreadIdEnricher ( ) , new ProcessIdEnricher ( ) , new NrLogLevelEnricher ( ) , new UTCTimestampEnricher ( ) )
44
43
. MinimumLevel . Information ( )
45
44
. ConfigureInMemoryLogSink ( )
46
45
. ConfigureEventLogSink ( ) ;
@@ -61,8 +60,8 @@ public static void ConfigureLogger(ILogConfig config)
61
60
62
61
var loggerConfig = new LoggerConfiguration ( )
63
62
. MinimumLevel . ControlledBy ( _loggingLevelSwitch )
63
+ . Enrich . With ( new ThreadIdEnricher ( ) , new ProcessIdEnricher ( ) , new NrLogLevelEnricher ( ) , new UTCTimestampEnricher ( ) )
64
64
. ConfigureAuditLogSink ( config )
65
- . Enrich . With ( new ThreadIdEnricher ( ) , new ProcessIdEnricher ( ) , new NrLogLevelEnricher ( ) )
66
65
. ConfigureFileSink ( config )
67
66
. ConfigureDebugSink ( ) ;
68
67
@@ -167,7 +166,7 @@ private static LoggerConfiguration ConfigureDebugSink(this LoggerConfiguration l
167
166
{
168
167
configuration
169
168
. ExcludeAuditLog ( )
170
- . WriteTo . Debug ( FileLogLayout ) ;
169
+ . WriteTo . Debug ( outputTemplate : FileLogLayout ) ;
171
170
} ) ;
172
171
#endif
173
172
return loggerConfiguration ;
@@ -184,7 +183,7 @@ private static LoggerConfiguration ConfigureConsoleSink(this LoggerConfiguration
184
183
{
185
184
configuration
186
185
. ExcludeAuditLog ( )
187
- . WriteTo . Console ( FileLogLayout ) ;
186
+ . WriteTo . Console ( outputTemplate : FileLogLayout ) ;
188
187
} )
189
188
) ;
190
189
}
@@ -248,9 +247,9 @@ private static LoggerConfiguration ConfigureAuditLogSink(this LoggerConfiguratio
248
247
/// </summary>
249
248
/// <param name="loggerConfiguration"></param>
250
249
/// <param name="fileName">The name of the file this appender will write to.</param>
251
- /// <param name="textFormatter "></param>
250
+ /// <param name="outputFormat "></param>
252
251
/// <remarks>This does not call appender.ActivateOptions or add the appender to the logger.</remarks>
253
- private static LoggerConfiguration ConfigureRollingLogSink ( this LoggerConfiguration loggerConfiguration , string fileName , ITextFormatter textFormatter )
252
+ private static LoggerConfiguration ConfigureRollingLogSink ( this LoggerConfiguration loggerConfiguration , string fileName , string outputFormat )
254
253
{
255
254
// check that the log file is accessible
256
255
try
@@ -272,7 +271,7 @@ private static LoggerConfiguration ConfigureRollingLogSink(this LoggerConfigurat
272
271
return loggerConfiguration
273
272
. WriteTo
274
273
. File ( path : fileName ,
275
- formatter : textFormatter ,
274
+ outputTemplate : outputFormat ,
276
275
fileSizeLimitBytes : 50 * 1024 * 1024 ,
277
276
encoding : Encoding . UTF8 ,
278
277
rollOnFileSizeLimit : true ,
0 commit comments