Search code examples
c#nhibernateserilog

How to set NHibernate.Logging.Serilog without appSettings?


The system is using the NHibernate.Logging.Serilog to log NHibernate.

It seems the only way to configure NHibernate.Logging.Serilog is the appSettings and serilog-settings-appsettings.

Is there a way to configure it by code without using appSettings?

Thanks in advance


Solution

  • serilog can be configured in code see here

    example

    Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Information()
        .WriteTo.Console()
        .WriteTo.File("log.txt",
            rollingInterval: RollingInterval.Day,
            rollOnFileSizeLimit: true)
        .CreateLogger();
    

    this should be called at the beginning before using NHibernate.