public void LoggerArgumentExceptions() { AmbientLogger <TestLogger> logger = new AmbientLogger <TestLogger>(_Logger.Global); Func <string> nullLambda = null; Exception nullException = null; Assert.ThrowsException <ArgumentNullException>(() => new AmbientLogger(null !)); Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullLambda !, "category", AmbientLogLevel.Information)); Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullException !, "category", AmbientLogLevel.Information)); Assert.ThrowsException <ArgumentNullException>(() => logger.Log("message", nullException !, "category", AmbientLogLevel.Information)); Assert.ThrowsException <ArgumentNullException>(() => logger.Log(() => "message", nullException !, "category", AmbientLogLevel.Information)); Assert.ThrowsException <ArgumentNullException>(() => logger.Log(nullLambda !, new ApplicationException(), "category", AmbientLogLevel.Information)); }
public async Task LoggerSettings() { BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest"); settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-LogLevel", AmbientLogLevel.Error.ToString()); settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-TypeFilter", "AllowedLoggerType"); settingsSet.ChangeSetting(nameof(BasicAmbientLogger) + "-CategoryFilter", "AllowedCategory"); using (ScopedLocalServiceOverride <IAmbientSettingsSet> o = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet)) { AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>(); logger.Log(new ApplicationException()); AmbientLogger <TestLogger> testlogger = new AmbientLogger <TestLogger>(); testlogger.Log(new ApplicationException()); testlogger.Log(new ApplicationException(), "category", AmbientLogLevel.Information); testlogger.Log("test message"); testlogger.Log(() => "test message"); testlogger.Log("test message", "category", AmbientLogLevel.Information); testlogger.Log("test message", "AllowedCategory", AmbientLogLevel.Information); testlogger.Log("Exception during test", new ApplicationException()); testlogger.Log(() => "Exception during test", new ApplicationException()); testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information); testlogger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); testlogger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information); if (_Logger.Local != null) { await _Logger.Local.Flush(); } } }
public void LoggerNone() { using (new ScopedLocalServiceOverride <IAmbientLogger>(null)) { AmbientLogger <TestLogger> logger = new AmbientLogger <TestLogger>(); logger.Log(new ApplicationException()); logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information); logger.Log("test message"); logger.Log(() => "test message"); logger.Log("test message", "category", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException()); logger.Log(() => "Exception during test", new ApplicationException()); logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); } }
public async Task LoggerDefault() { AmbientLogger logger = new AmbientLogger(typeof(TestLogger)); logger.Log(new ApplicationException()); logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information); logger.Log("test message"); logger.Log(() => "test message"); logger.Log("test message", "category", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException()); logger.Log(() => "Exception during test", new ApplicationException()); logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); if (_Logger.Global != null) { await _Logger.Global.Flush(); } }
public async Task LoggerExplicitSettings() { BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet("LoggerSettingsTest"); settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-LogLevel", AmbientLogLevel.Error.ToString()); settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-TypeBlock", ".*[Bb]lock.*"); settingsSet.ChangeSetting(nameof(AmbientLogFilter) + "-CategoryBlock", ".*[Bb]lock.*"); AmbientLogger <AllowedLoggerType> logger = new AmbientLogger <AllowedLoggerType>(_Logger.Global, settingsSet); logger.Log(new ApplicationException()); logger.Log(new ApplicationException(), "category", AmbientLogLevel.Information); logger.Log("test message"); logger.Log(() => "test message"); logger.Log("test message", "category", AmbientLogLevel.Information); logger.Log("test message", "AllowedCategory", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException()); logger.Log(() => "Exception during test", new ApplicationException()); logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException(), "category", AmbientLogLevel.Information); logger.Log("Exception during test", new ApplicationException(), "AllowedCategory", AmbientLogLevel.Information); if (_Logger.Global != null) { await _Logger.Global.Flush(); } }
/// <summary> /// Log that the assembly was loaded. /// </summary> /// <param name="assembly">The assembly that was loaded.</param> public static void LogLoaded(this Assembly assembly) { Logger.Log("AssemblyLoaded: " + assembly.FullName, "Lifetime", AmbientLogLevel.Trace); }