Add date to log file name in Logging Application Block

前端 未结 2 2033
离开以前
离开以前 2021-01-21 12:48

I\'m using the Microsoft Logging Application Block (version 5 beta 2) and I\'m trying to dynamically set the file name of a log file to the year month and day (and then write a

2条回答
  •  难免孤独
    2021-01-21 13:09

    @Robertc, I know this question has been marked but I think I have a trick that you can use for your next project : Use your own environment variable!

    E.g. Before you make any call to the Logging Block

    Environment.SetEnvironmentVariable("MYDATE", "15/07/2010"); // << change the hardcoded date to get from DateTime
    Debug.WriteLine (Environment.ExpandEnvironmentVariables(@"c:\Log\Log_%MYDATE%.log"));
    

    In your app.config, in the appropriate Rolling flat file trace listener

    FileName=Log_%MYDATE%.log
    

    Note: This trick will only work if you restart your application daily.

提交回复
热议问题