我正在使用MS EnterpriseLibrary.Logging并且工作正常,但日志文件放在程序可执行文件目录中。
如何将我的日志文件放在单个用户的applicationData文件夹中?
我正在谈论的文件夹是你通过调用获得的文件夹:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)I'm using MS EnterpriseLibrary.Logging and that works perfectly but the log file(s) are placed in the program executable directory.
How do I get it to place my log files in individual user's applicationData folder?
The folder I'm talking about is the one you get by calling:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)最满意答案
您应该能够在日志文件路径中使用环境变量。 我相信Environment.SpecialFolder.ApplicationData将等同于%APPDATA% 。
因此,您可以将fileName设置为: %APPDATA%\ MyApplication \ Logs \ trace.log还将在运行时为您创建目录结构,因此您无需显式创建文件夹。
配置文件看起来像:
<add fileName="%APPDATA%\MyApplication\Logs\trace.log" header="" footer="" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" name="Flat File Destination" />You should be able to use environment variables in your logfile path. I believe that Environment.SpecialFolder.ApplicationData would be equivalent to %APPDATA%.
So you can set the fileName to: %APPDATA%\MyApplication\Logs\trace.log The directory structure will also be created for you at runtime so you don't have to explicitly create the folders.
The configuration file would look something like:
<add fileName="%APPDATA%\MyApplication\Logs\trace.log" header="" footer="" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" name="Flat File Destination" />更多推荐
发布评论