10
10
using Serilog . Core ;
11
11
using Serilog . Formatting ;
12
12
using Logger = NewRelic . Agent . Core . Logging . Logger ;
13
+ using NewRelic . Agent . Core . Logging ;
13
14
14
15
namespace NewRelic . Agent . Core
15
16
{
@@ -42,6 +43,8 @@ public static class LoggerBootstrapper
42
43
43
44
private static LoggingLevelSwitch _loggingLevelSwitch = new LoggingLevelSwitch ( ) ;
44
45
46
+ private static InMemorySink _inMemorySink = new InMemorySink ( ) ;
47
+
45
48
public static void UpdateLoggingLevel ( string newLogLevel )
46
49
{
47
50
_loggingLevelSwitch . MinimumLevel = newLogLevel . MapToSerilogLogLevel ( ) ;
@@ -53,11 +56,9 @@ public static void Initialize()
53
56
. Enrich . With ( new ThreadIdEnricher ( ) )
54
57
. Enrich . With ( new ProcessIdEnricher ( ) )
55
58
. MinimumLevel . Information ( )
56
- . ConfigureInMemoryLogSink ( )
59
+ . ConfigureInMemoryLogSink ( ) ;
57
60
// TODO: implement event log sink
58
- //.ConfigureEventLogSink()
59
- // TODO: Remove console log sink when in-memory sink is implemented
60
- . ConfigureConsoleSink ( ) ;
61
+ //.ConfigureEventLogSink();
61
62
62
63
// set the global Serilog logger to our startup logger instance, this gets replaced when ConfigureLogger() is called
63
64
Serilog . Log . Logger = startupLoggerConfig . CreateLogger ( ) ;
@@ -103,13 +104,12 @@ public static void ConfigureLogger(ILogConfig config)
103
104
104
105
private static void EchoInMemoryLogsToConfiguredLogger ( Serilog . ILogger configuredLogger )
105
106
{
106
- // TODO: copy logs from inMemory logger and emit them to Serilog.Log.Logger
107
- // possible example:
108
- //foreach (LogEvent logEvent in InMemorySink.Instance.LogEvents)
109
- //{
110
- // configuredLogger.Write(logEvent.Level, logEvent.Exception, logEvent.MessageTemplate.Render(logEvent.Properties));
111
- //}
112
- //InMemorySink.Instance.Dispose();
107
+ foreach ( var logEvent in _inMemorySink . LogEvents )
108
+ {
109
+ configuredLogger . Write ( logEvent ) ;
110
+ }
111
+
112
+ _inMemorySink . Dispose ( ) ;
113
113
}
114
114
115
115
/// <summary>
@@ -133,9 +133,14 @@ private static void SetupLogLevel(ILogConfig config)
133
133
134
134
private static LoggerConfiguration ConfigureInMemoryLogSink ( this LoggerConfiguration loggerConfiguration )
135
135
{
136
- // TODO Configure the (yet-to-be-implemented) in-memory sink
137
-
138
- return loggerConfiguration ;
136
+ // formatter not needed since this will be pushed to other sinks for output.
137
+ return loggerConfiguration
138
+ . WriteTo . Logger ( configuration =>
139
+ {
140
+ configuration
141
+ . ExcludeAuditLog ( )
142
+ . WriteTo . Sink ( _inMemorySink ) ;
143
+ } ) ;
139
144
}
140
145
141
146
// TODO: Implement EventLog support, see commented package reference in Core.csproj
0 commit comments