How can I query the path to an NLog log file?

后端 未结 3 2498
余生分开走
余生分开走 2021-02-20 12:36

I\'ve configured a file target for NLog as follows:


  
    

        
3条回答
  •  情书的邮戳
    2021-02-20 13:12

    You could use nLog's api inside of code instead of an xml configuration file. Then, in your application, you assign the log's file path to a variable, and use that variable as the target's filename. You can access that variable, OR change it anytime you like (my snippet, here, is defined inside of a class).

    Private MainNlogConfig As New LoggingConfiguration()
    Dim localrule As New LoggingRule(*, LogLevel.Info, locallogtarget)
    MainNlogConfig..AddTarget("file", locallogtarget)
    
    With locallogtarget
        .Layout = "${longdate} ${logger} ${message}"
        .FileName = appdir & appName & ".log"  '----->LOOK HERE!
    End With
    LogManager.Configuration = MainNlogConfig
    

提交回复
热议问题