public void LogDoesNotAddEmptyScopeToExtendedProperties() { LogEntry logEntry = null; var exception = new Exception("Some random exception"); var eventId = new EventId(15, "SomeEvent"); var state = new Dictionary <string, string>(); var loggerMock = new Mock <ILogger>(); loggerMock.Setup(lm => lm.Level).Returns(LogLevel.Debug); loggerMock .Setup(lm => lm.Log(It.IsAny <LogEntry>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Callback <LogEntry, string, string, int>((le, s1, s2, i) => logEntry = le); var rlLogger = new RockLibLogger(loggerMock.Object, "SomeCategory"); using (rlLogger.BeginScope("a")) using (rlLogger.BeginScope("b")) using (rlLogger.BeginScope("c")) { } rlLogger.Log(MSE.LogLevel.Debug, eventId, state, exception, (dictionary, ex) => "Simple message"); logEntry.ExtendedProperties.Should().NotContainKey("Microsoft.Extensions.Logging.Scope"); }
public void BeginScopeAddsObjectToTheScopeStack() { var loggerMock = new Mock <ILogger>(); var rlLogger = new RockLibLogger(loggerMock.Object, null); rlLogger.GetScope().Should().BeEmpty(); rlLogger.BeginScope("a"); rlLogger.GetScope().Should().Equal(new object[] { "a" }); rlLogger.BeginScope("b"); rlLogger.GetScope().Should().Equal(new object[] { "b", "a" }); rlLogger.BeginScope("c"); rlLogger.GetScope().Should().Equal(new object[] { "c", "b", "a" }); }
public void BeginScopeMethodHappyPath2() { var logger = new MockLogger().Object; var rockLibLogger = new RockLibLogger(logger, "MyCategory", null); var token = rockLibLogger.BeginScope("Hello, world!"); token.Should().BeNull(); }
public void DisposingTheObjectReturnedFromBeginScopePopsTheScopeStack() { var loggerMock = new Mock <ILogger>(); var rlLogger = new RockLibLogger(loggerMock.Object, null); using (rlLogger.BeginScope("a")) { using (rlLogger.BeginScope("b")) { using (rlLogger.BeginScope("c")) { rlLogger.GetScope().Should().Equal(new object[] { "c", "b", "a" }); } rlLogger.GetScope().Should().Equal(new object[] { "b", "a" }); } rlLogger.GetScope().Should().Equal(new object[] { "a" }); } rlLogger.GetScope().Should().BeEmpty(); }
public void BeginScopeMethodHappyPath1() { var expectedToken = new Mock <IDisposable>().Object; var mockScopeProvider = new Mock <IExternalScopeProvider>(); mockScopeProvider.Setup(m => m.Push(It.IsAny <object>())).Returns(expectedToken); var logger = new MockLogger().Object; var rockLibLogger = new RockLibLogger(logger, "MyCategory", mockScopeProvider.Object); var token = rockLibLogger.BeginScope("Hello, world!"); mockScopeProvider.Verify(m => m.Push("Hello, world!"), Times.Once()); token.Should().BeSameAs(expectedToken); }