public void QueueHangfire_Logging_LogLevels(LogLevel logLevel) { var hangFireLogger = new HangfireLogProvider(TestLoggerFactory); var sourceContext = "QueueHangfireUnitTests"; var logger = hangFireLogger.GetLogger(sourceContext); var testString = "Test: QueueHangfire_Logging"; logger.Log(logLevel, () => testString); }
public void QueueHangfire_Logging_LogLevels_Bogus() { var hangFireLogger = new HangfireLogProvider(TestLoggerFactory); var sourceContext = "QueueHangfireUnitTests"; var logger = hangFireLogger.GetLogger(sourceContext); Func <bool> fx = () => logger.Log((LogLevel)100, TestString); fx.Should().Throw <ArgumentOutOfRangeException>(); }
/// <summary> /// Registers the hangfire queue. /// </summary> /// <param name="services">The services.</param> /// <param name="connectionString">The connection string.</param> /// <param name="loggerFactory">The logger factory.</param> public static void AddHangfireQueue( this IServiceCollection services, string connectionString, IPureLoggerFactory loggerFactory) { services.AddHangfire ( config => { var logProvider = new HangfireLogProvider(loggerFactory); var storage = RetryGetHangfireStorage(connectionString); config .UseLogProvider(logProvider) .UseStorage(storage); } ); }
public void QueueHangfire_Logging() { var hangFireLogger = new HangfireLogProvider(TestLoggerFactory); var sourceContext = "QueueHangfireUnitTests"; var logger = hangFireLogger.GetLogger(sourceContext); var testString = "Test: QueueHangfire_Logging"; using (TestCorrelator.CreateContext()) { logger.Log(LogLevel.Debug, () => testString); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.Properties["State"].ToString() .Should().Be(testString.ToDoubleQuoted()); TestCorrelator.GetLogEventsFromCurrentContext() .Should().ContainSingle() .Which.Properties["SourceContext"].ToString() .Should().Be(sourceContext.ToDoubleQuoted()); } }