Get ApplicationDataFolder-Direction in XML



I am using log4net to save logfiles via c#-application. The requiered app.config-data looks like this.





<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net" >
<param name="File" type="log4net.Util.PatternString" value="C:\Users\Alex\AppData\Roaming\Log\logFile.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%date [%thread] %-5level - %message%newline"/>
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<category name="testApp.LoggingExample">
<priority value="ALL" />
</category>
</log4net>
</configuration>



The XML-File saves the logfile to the direction: C:\Users\Alex\AppData\Roaming\Log. If anybode use this c# application on a other pc (with a other username instead of alex) the logfile won't and can't be saved, because the direction won't exist.


If i ender "%appdata% in a microsoft-window i will get C:\Users\Alex\AppData\Roaming. It's the same function like



Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)


Is it possible to change the value = "C:\Users\Alex\AppData\Roaming\Log\logFile.txt" more dynamically in the XML-Data, for example like:



<param name="File" type="log4net.Util.PatternString" value="${APP_DATA}\Log\logFile.txt" />


Unfortunately, it doesn't work. So do anybody know a other solution for my problem? I hope you can help me. Thank you a lot!


No comments:

Post a Comment