damianh / LibLog

LibLog is a single file for you to either copy/paste or install via nuget, into your library/framework/application to provide a logging abstraction.
MIT License
929 stars 153 forks source link

LibLog 4.2.6 + SeriLog + NUnit: Logger in a subclass does not work #253

Closed swidz closed 5 years ago

swidz commented 5 years ago

Hi, I have noticed the following issue, and wonder if there is something I miss or if there is some problem with the LibLog + SeriLog + NUnit combination setup. I have two classes, where the second is extending the first one. Both have their own private Logger properties. In the NUnit test setup I configure SeriLog Logger. When analyzing output in Visual Studio Test Explorer I can only see entries from class A but no entries from class B

public class A 
{
    private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();
    public void Foo()
    {
        Logger.DebugFormat("{MethodName} called", nameof(Foo))
    }
}
public class B : A
{
    private static readonly ILog Logger = LogProvider.GetCurrentClassLogger();
    public void SomeOtherMethod()
    {
        //This is not visible in tests output
        Logger.DebugFormat("{MethodName} called", nameof(SomeOtherMethod));
    }
} 
    [SetUpFixture]
    public class MyTestsSetup
    {
        [OneTimeSetUp]
        public void SetupTests()
        {
            //Initiate Logger
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Console()
                .CreateLogger();
        }

        [OneTimeTearDown]
        public void DisposeTests()
        {
            Log.CloseAndFlush();
        }
    }
[TestFixture]
public class MyTestClass
{
    [Test]
    public void MyTest1()
    {
        var a = new A();
        a.Foo(); //Log entries are visible in the test output
    }

    [Test]
    public void MyTest1()
    {
        var b = new B();
        b.SomeOtherMethod(); //Log entries are NOT visible in the test output
    }
}

I am using .NET 4.6.1 LibLog 4.2.6 SeriLog 2.8 SeiLog.Sinks.Console 3.1.1 NUnit 3.12

Best regards, Sebastian

swidz commented 5 years ago

This issue is related to NUnit. When running in console, everything works as expected.