Custom filename in a rolling Log4Net logfile?

后端 未结 6 1620
刺人心
刺人心 2020-12-24 07:50

We have a ASP .Net application whereby we use Log4Net to log details within the app - nothing new there - and the rolling log filenames are in the usual format of:



        
相关标签:
6条回答
  • 2020-12-24 08:32

    Checkout the RollingPatternFileAppender, just like the rollingfileappender plus dynamic file name http://mysite.verizon.net/vze14bhji

    0 讨论(0)
  • 2020-12-24 08:35

    look for log4net Context Properties...

    in your code :

    log4net.GlobalContext.Properties["id"] = "12345";
    

    then

    log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo("configPath"));
    

    in the log4net config file:

    <file type="log4net.Util.PatternString"
                value="%property{id}rolling-log.txt" />
    
    0 讨论(0)
  • 2020-12-24 08:49

    You can write a custom layout by inherit from XmlLayoutBase.

    0 讨论(0)
  • 2020-12-24 08:51
    <file type="log4net.Util.PatternString">
      <conversionPattern value="C:\Logs\log-%date{ yyyy.MM.dd.HH.mm.ss}-[%processid].log" />
    </file>
    

    from here

    0 讨论(0)
  • 2020-12-24 08:51

    I don't think that log file per user is possible but you can write custom layer between log4net and your application which prepends user id before writing to log.

    0 讨论(0)
  • 2020-12-24 08:54

    I believe the Log4Net configuration file supports environment variables (e.g. USERNAME) as well as customizable patterns which should give you what you want.

    Look at "PatternString for pattern based configuration" in the Log4Net V1.2.10 release notes.

    0 讨论(0)
提交回复
热议问题