Log4net output to My Documents

后端 未结 3 481
执念已碎
执念已碎 2021-01-17 17:51

In our C# app, we write files to Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments). Our log4net logfile should go there too, so we\'ve defined

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 18:24

    There seem to be at least 2 approaches. The simplest is kind of a hack:

    1. Specify a custom environment variable to indicate the root path in you log4net config:

    2. At startup, before initializing logging, set this environment variable value:

      Environment.SetEnvironmentVariable("MYAPP_USER_ROOTFOLDER", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

    The more complicated but recommended approach is explained here: http://marc.info/?l=log4net-user&m=110142086820117&w=2 and here http://ziqbalbh.com/articles/log4net-another-way-to-change-log-file-location-on-runtime/

提交回复
热议问题