LogManager ILogger

I am using ServiceStack 5.8.0 in a netcore3.1 ASP.NET project using the standard template.

Way down deep in my domain I am using ILogger (Microsoft.Extensions.Logging) to do all my logging.

I have registered a console logger in the standard ASP.NET way (in Program.cs) for now for testing:

public static IWebHost BuildWebHost(string[] args)
            return WebHost.CreateDefaultBuilder(args)
                .ConfigureLogging((context, builder) => builder.AddConsole())

Now, my code uses that logger at runtime, but I also wanted ServiceStack to use that logger as well.

In AppHost.cs, what should I be doing with LogManager.LogFactory to force ServiceStack code to use the pre-defined logger from above? So that I only have to change my implementation of the logger in Program.cs only?

By default the .NET Core AppHostBase should already be configured to use the NetCoreLogFactory which delegates all ServiceStack ILog to Microsoft’s ILogger.

Great thanks.

That feature is not so obvious from the outset - would be good to make a note of that in the .NetCore docs, or Logging docs.


1 Like