You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
app.config does not support Windows environment variables. There could be a few solutions:
The application alters the config file at startup. The drawbak is, this requires high privilege, and miss trace info before the app codes run.
Installer to alter the config during installation. This requires a lot scripting.
It will be more convenient to have
initializeData="%ProgramData%\My Company{ApplicationName}-{LocalDateTime:yyyy-MM-dd}.log"
Documentation later upon next release:
You may use Windows environment variable in front the the file path. For example:
initializeData="%ProgramData%\My Company{ApplicationName}-{LocalDateTime:yyyy-MM-dd}.log"
Please note, app.config does not support interpreting environment variables, thus you can not apply the same to TextWriterTraceListener in System.Diagnostics.
The text was updated successfully, but these errors were encountered:
To get something similar to work, I derived classes from TextWriterTraceListener (available in all versions) and XmlWriterTraceListener (available in .Net 2.0+, .NET Core 3+):
using System;using System.Diagnostics;// To the extent possible under law, Erich Stehr has waived all copyright and related or neighboring rights to this work. This work is published from: United States.namespacens1{publicclassTextWriterTraceListener: System.Diagnostics.TextWriterTraceListener
{publicTextWriterTraceListener(stringinitializeData):base(Environment.ExpandEnvironmentVariables(initializeData)){}publicTextWriterTraceListener(stringinitializeData,stringname):base(Environment.ExpandEnvironmentVariables(initializeData), name){}}}
With this exposed in a myprog.exe, the App.config simply needed a shared listener with type="ns1.TextWriterTraceListener, myprog" initializeData="%ProgramData%\My Company{ApplicationName}-{LocalDateTime:yyyy-MM-dd}.log" to place the log appropriately.
Obviously, I'm hiding the other constructors, but I can't use those from the App.config, and can inject the expanded path into the System.Diagnostics class itself from code.
app.config does not support Windows environment variables. There could be a few solutions:
The application alters the config file at startup. The drawbak is, this requires high privilege, and miss trace info before the app codes run.
Installer to alter the config during installation. This requires a lot scripting.
It will be more convenient to have
initializeData="%ProgramData%\My Company{ApplicationName}-{LocalDateTime:yyyy-MM-dd}.log"
Documentation later upon next release:
You may use Windows environment variable in front the the file path. For example:
initializeData="%ProgramData%\My Company{ApplicationName}-{LocalDateTime:yyyy-MM-dd}.log"
Please note, app.config does not support interpreting environment variables, thus you can not apply the same to TextWriterTraceListener in System.Diagnostics.
The text was updated successfully, but these errors were encountered: