Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Fix logging issue when log context level conflicts with logger already captured level #15057

Merged
merged 11 commits into from
Jan 10, 2025
24 changes: 24 additions & 0 deletions dotnet/test/common/Internal/Logging/LogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@ public class LogTest
private TestLogHandler testLogHandler;
private ILogger logger;

private void ResetGlobalLog()
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved
{
Log.SetLevel(LogEventLevel.Info);
Log.Handlers.Clear().Handlers.Add(new ConsoleLogHandler());
}

[SetUp]
public void SetUp()
{
ResetGlobalLog();

testLogHandler = new TestLogHandler();
logger = Log.GetLogger<LogTest>();
}

[TearDown]
public void TearDown()
{
ResetGlobalLog();
}

[Test]
public void LoggerShouldEmitEvent()
{
Expand Down Expand Up @@ -160,6 +174,16 @@ public void ContextShouldChangeLevel()
Assert.That(logger.Level, Is.EqualTo(LogEventLevel.Warn));
}

[Test]
public void ContextShouldEmitMessages()
{
using var context = Log.CreateContext(LogEventLevel.Trace).Handlers.Add(testLogHandler);

logger.Trace("test message");

Assert.That(testLogHandler.Events.Count, Is.EqualTo(1));
}

[Test]
public void ShouldCreateContextWithCustomHandler()
{
Expand Down
Loading