Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log to user's ApplicationData folder using Enterprise Library Logging?

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)
like image 976
MüllerDK Avatar asked Jun 10 '26 02:06

MüllerDK


1 Answers

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" />
like image 69
Randy supports Monica Avatar answered Jun 16 '26 05:06

Randy supports Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!