Switching out NLog

Hi! I’ve nearly succeeded in switching the logging functionality to Serilog (logging to a seq server instance) described in this topic.

However the Litium application lifecycle starts before the IPreSetup is run where the configuration is being made, and because of that a log file is being created by NLog with
Litium.Owin.Lifecycle.Application - Application starting

Litium.Owin.Lifecycle.Application - Litium (application domain 2) created in…

After that everything is being logged using Serilog. Is there any earlier stage I can hook in the configuration?

Litium version: 7.6.1

If you use the IInitTask instead it will be initiated as early as possible in initiating states.

Disconnecting Litium from using the NLog will also make the log collection that exists in Litium Cloud to not work and may impact failure detection times on the customer sites.

Option to not replace the NLog to Serilog if the loggshipping to Seq is the requested function, you can instead use the NLog target directly that can ship the log from NLog into Seq.

If the requirement is to use Serilog for other functionality you should forward all loggs from Serilog to NLog. It is required that you add the Litium.Cloud.NLog.Extensions Nuget package into your project to get this to work.

            // Nlog configuration to connect to Litium Cloud
            var nlogFactory = NLogBuilder
                .ConfigureNLog(new LoggingConfiguration())
                .ConfigureLitiumNLog();

            var nlogOptions = new NLogProviderOptions
            {
                IncludeActivtyIdsWithBeginScope = true,
                IncludeScopes = true
            };

            var loggingProviders = new LoggerProviderCollection();
            loggingProviders.AddProvider(new NLogLoggerProvider(nlogOptions, nlogFactory));
            // -- //

            Log.Logger = new LoggerConfiguration()
                .WriteTo.Providers(loggingProviders) // <-- Connect Serilog to send into the NLog provider that is configured by Litium Cloud
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .CreateLogger();

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