如何使用Enterprise Library Logging登录用户的ApplicationData文件夹?(How to log to user's ApplicationData fol

编程入门 行业动态 更新时间:2024-10-27 05:21:50
如何使用Enterprise Library Logging登录用户的ApplicationData文件夹?(How to log to user's ApplicationData folder using Enterprise Library Logging?)

我正在使用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" />

更多推荐

本文发布于:2023-07-05 01:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文件夹   用户   Library   Enterprise

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!