public void Log_messages_with_unknown_Category_throws_ArgumentOutOfRangeException() { LogEvent logEvent = null; var logger = DelegatingSink.GetLogger(le => logEvent = le); const string message = "This is an Exception message"; var target = new SerilogLoggerFacade(logger); Assert.Throws <ArgumentOutOfRangeException>(() => target.Log(message, (Category)(-1), Priority.None)); Assert.Null(logEvent); }
private static void TestCategoryToLogEventLevelMap(Category category, LogEventLevel expectedLogEventLevel) { LogEvent logEvent = null; var logger = DelegatingSink.GetLogger(le => logEvent = le); var message = $"This is a {category} message"; var target = new SerilogLoggerFacade(logger); target.Log(message, category, Priority.None); Assert.Equal(expectedLogEventLevel, logEvent.Level); Assert.Equal(message, logEvent.MessageTemplate.Text); }
public void Serilog_Log_Logger_is_used_by_default_if_no_ILogger_injected_via_constructor() { LogEvent logEvent = null; Log.Logger = DelegatingSink.GetLogger(le => logEvent = le); const string message = "This is a Debug message"; var target = new SerilogLoggerFacade(); target.Log(message, Category.Debug, Priority.None); Assert.Equal(LogEventLevel.Debug, logEvent.Level); }
public void Log_messages_have_SourceContext_set_to_SerilogLoggerFacade_FullName() { LogEvent logEvent = null; var logger = DelegatingSink.GetLogger(le => logEvent = le); var target = new SerilogLoggerFacade(logger); target.Log(string.Empty, Category.Exception, Priority.None); Assert.True(logEvent.Properties.ContainsKey("SourceContext")); var sourceContext = logEvent.Properties["SourceContext"].LiteralValue(); Assert.Equal(typeof(SerilogLoggerFacade).FullName, sourceContext); }
private static void TestPriorityToPropertyMap(Priority priority, string propertyName, string expectedValue) { LogEvent logEvent = null; var logger = DelegatingSink.GetLogger(le => logEvent = le); var target = new SerilogLoggerFacade(logger); target.Log(string.Empty, Category.Exception, priority); Assert.True(logEvent.Properties.ContainsKey(propertyName)); var priorityValue = logEvent.Properties[propertyName].LiteralValue(); Assert.Equal(expectedValue, priorityValue); }