簡體   English   中英

如何使用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)

您應該能夠在日志文件路徑中使用環境變量。 我相信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" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM