Serilog RollingFile

前端 未结 7 1309
囚心锁ツ
囚心锁ツ 2021-01-07 19:45

I am trying to use WriteTo.RollingFile with Serilog as the following:

var log = new LoggerConfiguration().WriteTo.RollingFile(
                    @\"F:\\log         


        
7条回答
  •  星月不相逢
    2021-01-07 19:55

    Here is a way to use Serilog with a web.config in an asp.net MVC 4/5 app.

    In your web.config add the following:

    
    
    
    
    
    
    
    

    Then in Application_Start of global.asax add the following:

    // Get application base directory
    string basedir = AppDomain.CurrentDomain.BaseDirectory;
    
    // Setup Serilog for logging
    Log.Logger = new LoggerConfiguration()
                .ReadFrom.AppSettings()
                .WriteTo.RollingFile(basedir + "/Logs/log-{Date}.txt")
                .CreateLogger();
    

提交回复
热议问题