I am using Microsoft Enterprise Library 5.0 Optional Update 1 for logging. I've got a declared section in my app.config file as follows:
<loggingConfiguration name="LLamasoftLoggingConfiguration" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="XML Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.XmlTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.XmlTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="%ALLUSERSPROFILE%\CompanyName\AppName\Diagnostics\ErrorLog.xml" traceOutputOptions="None" />
</listeners>
...
</loggingConfiguration>
When I run the application and get down to using the logging, e.g.,
logWriter = Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
logWriter.Write(logEntry);
I'll get a DirectoryNotFoundException with the text: Could not find a part of the path 'D:\Project\Application\bin\x86\Debug\%ALLUSERSPROFILE%\CompanyName\AppName\Diagnostics\ErrorLog.xml'.
When I use an absolute path like 'C:\ProgramData\CompanyName\AppName\Diagnostics\ErrorLog.xml'
it works.
I see a number of references saying I should be able to use environment vars in the log file path but, no matter which I try, they get appended to the current execution directory path. The references also say that the logging system will create the folder if it does not exist but I have to ensure that it exists.
This is my first use of the Enterprise Logging application block so I don't know whether the behavior has changed between versions and if this one just has these quirks. For now, I've hard-coded the path into my app.config file but for the final version this should be dynamically determined.
Suggestions appreciated.