@@ -123,27 +123,17 @@ public void Logger_writes_through_factory()
123123/// <summary>
124124/// Test implementation of DeferredLoggerFactory that mirrors the production code.
125125/// </summary>
126- class TestDeferredLoggerFactory : NServiceBus . Logging . ILoggerFactory
126+ class TestDeferredLoggerFactory ( LogLevel level ) :
127+ ILoggerFactory
127128{
128- LogLevel level ;
129- bool isDebugEnabled ;
130- bool isInfoEnabled ;
131- bool isWarnEnabled ;
132- bool isErrorEnabled ;
133- bool isFatalEnabled ;
129+ bool isDebugEnabled = LogLevel . Debug >= level ;
130+ bool isInfoEnabled = LogLevel . Info >= level ;
131+ bool isWarnEnabled = LogLevel . Warn >= level ;
132+ bool isErrorEnabled = LogLevel . Error >= level ;
133+ bool isFatalEnabled = LogLevel . Fatal >= level ;
134134
135135 public ConcurrentDictionary < string , ConcurrentQueue < ( LogLevel level , string message ) > > DeferredLogs { get ; } = [ ] ;
136136
137- public TestDeferredLoggerFactory ( LogLevel level )
138- {
139- this . level = level ;
140- isDebugEnabled = LogLevel . Debug >= level ;
141- isInfoEnabled = LogLevel . Info >= level ;
142- isWarnEnabled = LogLevel . Warn >= level ;
143- isErrorEnabled = LogLevel . Error >= level ;
144- isFatalEnabled = LogLevel . Fatal >= level ;
145- }
146-
147137 public ILog GetLogger ( Type type ) =>
148138 GetLogger ( type . FullName ! ) ;
149139
@@ -171,65 +161,57 @@ public void Write(string name, LogLevel messageLevel, string message)
171161/// <summary>
172162/// Test implementation of NamedLogger that mirrors the production code.
173163/// </summary>
174- class TestNamedLogger : ILog
164+ class TestNamedLogger ( string name , TestDeferredLoggerFactory factory ) :
165+ ILog
175166{
176- string name ;
177- TestDeferredLoggerFactory factory ;
178-
179- public TestNamedLogger ( string name , TestDeferredLoggerFactory factory )
180- {
181- this . name = name ;
182- this . factory = factory ;
183- }
184-
185167 public bool IsDebugEnabled { get ; internal set ; }
186168 public bool IsInfoEnabled { get ; internal set ; }
187169 public bool IsWarnEnabled { get ; internal set ; }
188170 public bool IsErrorEnabled { get ; internal set ; }
189171 public bool IsFatalEnabled { get ; internal set ; }
190172
191- public void Debug ( string message ) =>
192- factory . Write ( name , LogLevel . Debug , message ) ;
173+ public void Debug ( string ? message ) =>
174+ factory . Write ( name , LogLevel . Debug , message ?? "" ) ;
193175
194- public void Debug ( string message , Exception exception ) =>
195- factory . Write ( name , LogLevel . Debug , message + Environment . NewLine + exception ) ;
176+ public void Debug ( string ? message , Exception ? exception ) =>
177+ factory . Write ( name , LogLevel . Debug , ( message ?? "" ) + Environment . NewLine + exception ) ;
196178
197- public void DebugFormat ( string format , params object [ ] args ) =>
179+ public void DebugFormat ( string format , params object ? [ ] args ) =>
198180 factory . Write ( name , LogLevel . Debug , string . Format ( format , args ) ) ;
199181
200- public void Info ( string message ) =>
201- factory . Write ( name , LogLevel . Info , message ) ;
182+ public void Info ( string ? message ) =>
183+ factory . Write ( name , LogLevel . Info , message ?? "" ) ;
202184
203- public void Info ( string message , Exception exception ) =>
204- factory . Write ( name , LogLevel . Info , message + Environment . NewLine + exception ) ;
185+ public void Info ( string ? message , Exception ? exception ) =>
186+ factory . Write ( name , LogLevel . Info , ( message ?? "" ) + Environment . NewLine + exception ) ;
205187
206- public void InfoFormat ( string format , params object [ ] args ) =>
188+ public void InfoFormat ( string format , params object ? [ ] args ) =>
207189 factory . Write ( name , LogLevel . Info , string . Format ( format , args ) ) ;
208190
209- public void Warn ( string message ) =>
210- factory . Write ( name , LogLevel . Warn , message ) ;
191+ public void Warn ( string ? message ) =>
192+ factory . Write ( name , LogLevel . Warn , message ?? "" ) ;
211193
212- public void Warn ( string message , Exception exception ) =>
213- factory . Write ( name , LogLevel . Warn , message + Environment . NewLine + exception ) ;
194+ public void Warn ( string ? message , Exception ? exception ) =>
195+ factory . Write ( name , LogLevel . Warn , ( message ?? "" ) + Environment . NewLine + exception ) ;
214196
215- public void WarnFormat ( string format , params object [ ] args ) =>
197+ public void WarnFormat ( string format , params object ? [ ] args ) =>
216198 factory . Write ( name , LogLevel . Warn , string . Format ( format , args ) ) ;
217199
218- public void Error ( string message ) =>
219- factory . Write ( name , LogLevel . Error , message ) ;
200+ public void Error ( string ? message ) =>
201+ factory . Write ( name , LogLevel . Error , message ?? "" ) ;
220202
221- public void Error ( string message , Exception exception ) =>
222- factory . Write ( name , LogLevel . Error , message + Environment . NewLine + exception ) ;
203+ public void Error ( string ? message , Exception ? exception ) =>
204+ factory . Write ( name , LogLevel . Error , ( message ?? "" ) + Environment . NewLine + exception ) ;
223205
224- public void ErrorFormat ( string format , params object [ ] args ) =>
206+ public void ErrorFormat ( string format , params object ? [ ] args ) =>
225207 factory . Write ( name , LogLevel . Error , string . Format ( format , args ) ) ;
226208
227- public void Fatal ( string message ) =>
228- factory . Write ( name , LogLevel . Fatal , message ) ;
209+ public void Fatal ( string ? message ) =>
210+ factory . Write ( name , LogLevel . Fatal , message ?? "" ) ;
229211
230- public void Fatal ( string message , Exception exception ) =>
231- factory . Write ( name , LogLevel . Fatal , message + Environment . NewLine + exception ) ;
212+ public void Fatal ( string ? message , Exception ? exception ) =>
213+ factory . Write ( name , LogLevel . Fatal , ( message ?? "" ) + Environment . NewLine + exception ) ;
232214
233- public void FatalFormat ( string format , params object [ ] args ) =>
215+ public void FatalFormat ( string format , params object ? [ ] args ) =>
234216 factory . Write ( name , LogLevel . Fatal , string . Format ( format , args ) ) ;
235217}
0 commit comments