Litium 7.7.8 breaking change

Continuing the discussion from Litium 7.7.8 is released:

From 59989 - Logging improvements
“If you implemented your own Litium.Owin.Logging.ILog provider the provider need to be changed to use the Microsoft Logging Extension provider.”

We’ve inherited the code for our Litium solution and I’m not sure how our logging is built. @patric.forsgard Do you have any suggestion what to look for in the code to know if we have our own implementation of a Litium.Owin.Logging.ILog provider?

What’s you background for the change in the default implementation?

What you need to do is to implement your own Microsoft.Extensions.Logging.ILoggerProvider that will be registered as an logger provider, example

    public class MyLogger : Microsoft.Extensions.Logging.ILogger
    {
        public MyLogger(string categoryName)
        {
        }

        public IDisposable BeginScope<TState>(TState state)
        {
            throw new NotImplementedException();
        }

        public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel)
        {
            throw new NotImplementedException();
        }

        public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
        {
            throw new NotImplementedException();
        }
    }

    public class MyLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider
    {
        public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
        {
            return new MyLogger(categoryName);
        }

        public void Dispose()
        {
        }
    }

    public class MyLoggingProviderConfiguration : Litium.Runtime.IApplicationConfiguration
    {
        public void Configure(ApplicationConfigurationBuilder app)
        {
            app.ConfigureServices(services =>
            {
                services.AddLogging(configure =>
                {
                    configure.AddProvider(new MyLoggerProvider());
                });
            });
        }
    }

In many cases common logging providers already have implementation for the Microsoft Logging Extensions and then they can be used directly, see the links in the bug.

My question was how we would know if we are affected by the breaking change.

We’re using NLog.ILogger directly to write logs but we don’t have a custom implementation of the interface. Does that mean that we’re in the clear? Or do we need to change all usage of NLog.ILogger to use Microsoft.Extensions.Logging.ILogger instead?

If you have implemented your own logger that implements the Litium.Owin.Logging.ILog you will have new member-methods that need to be implemented and getting build errors; otherwise your code is not affected.

Using NLog.LogManager.GetLogger(cateogryName) is still possible and that will work as before, Litium still using Nlog for as the logging provider and all log record will end up in the same place.

To be better future compatible you should stop using NLog directly and instead inject the Microsoft.Extensions.Logging.ILogger into your implementations, then the logging will be configured in one place and can easy be changed to another logging provider without a need to change the caller code.

1 Like

Thank you for the clarification @patric.forsgard. :+1:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.