public void Configuring_With_Static_Log_Should_Write_Message() { var originalLocator = Locator.InternalLocator; try { Locator.InternalLocator = new InternalLocator(); var(seriLogger, target) = CreateSerilogger(LogLevel.Debug); Log.Logger = seriLogger; Locator.CurrentMutable.UseSerilogFullLogger(); Assert.Equal(0, target.Logs.Count); IEnableLogger logger = null; logger.Log().Debug <DummyObjectClass2>("This is a test."); Assert.Equal(1, target.Logs.Count); Assert.Equal("This is a test.", target.Logs.Last().message.Trim(NewLine).Trim()); } finally { Locator.InternalLocator = originalLocator; } }
public static IFullLogger Log(this IEnableLogger logger) { ILogManager service = Locator.Current.GetService <ILogManager>(); if (service == null) { throw new Exception("ILogManager is null. This should never happen, your dependency resolver is broken"); } return(service.GetLogger(logger.GetType())); }
/// <summary> /// Log returns the current logger object, which allows the object to /// log messages with the type name attached. /// </summary> /// <returns></returns> public static ILog Log(this IEnableLogger This) { // Prevent recursive meta-logging if (This is MemoizingMRUCache <int, ILog> ) { return(mruLogger); } lock (loggerCache) { return(loggerCache.Get(This.GetHashCode(), This)); } }
public void Configuring_With_PreConfigured_Log_Should_Write_Message() { var serilogLoggerAndTarget = GetActualSerilogLoggerAndTarget(); var target = serilogLoggerAndTarget.Target; Locator.CurrentMutable.UseSerilogFullLogger(serilogLoggerAndTarget.Logger); Assert.Equal(0, target.Logs.Count); IEnableLogger logger = null; // Will Fail logger.Log().Debug <DummyObjectClass2>("This is a test."); Assert.Equal(1, target.Logs.Count); Assert.Equal($"{typeof(DummyObjectClass2).FullName}: This is a test.", target.Logs.First()); }
public static Task <T> ErrorIfThrows <T>(this IEnableLogger This, Func <Task <T> > block, string message = null) { return(This.Log().LogIfThrows(LogLevel.Error, message, block)); }
public static void ErrorIfThrows(this IEnableLogger This, Action block, string message = null) { This.Log().LogIfThrows(LogLevel.Error, message, block); }
public static Task WarnIfThrows(this IEnableLogger This, Func <Task> block, string message = null) { return(This.Log().LogIfThrows(LogLevel.Warn, message, block)); }
public static void LogFatal(this IEnableLogger _, Exception exception) => _logger.LogFatal(exception);
public static void LogFatal(this IEnableLogger _, object classifier, Exception exception) => _logger.LogFatal(classifier, exception);
public static void LogFatal(this IEnableLogger _, object classifier, Exception exception, string message) => _logger.LogFatal(classifier, exception, message);
public static void LogError(this IEnableLogger _, Exception exception) => _logger.LogError(exception);
public static void LogWarning(this IEnableLogger _, string message) => _logger.LogWarning(message);
public static void LogWarning(this IEnableLogger _, object classifier, string message) => _logger.LogWarning(classifier, message);
public static void LogInformation(this IEnableLogger _, string message) => _logger.LogInformation(message);
public static void LogInformation(this IEnableLogger _, object classifier, string message) => _logger.LogInformation(classifier, message);