How to specify template, or tokens in filename of Enterprise Library Logging file listener

78 Views Asked by At

From what I read it appears, that enterprise library does not allow tokens in filename, which is very strange, because all other logging solutions do.

It's very confusing, I am definetly missing something. Cause I am not even able to specify Process name in flat or lolling file listener.

NLog

<target name="txtFile"
    xsi:type="File"
    fileName="${cached:cached=true:inner=${date:format=yyyy-MM-dd HH-mm-ss}}.txt"
    layout="${longdate} ${level} ${message}"/>

Log4Net

<file type="log4net.Util.PatternString" value="~/App_Data/%property{LogName}" />
1

There are 1 best solutions below

0
Andrey Ershov On BEST ANSWER

The only solution I know (excluding programmatic setup) now is using Environment Variables on Process Level

<add name="loggingErrorsLog"                
     fileName="%LOGS_DIR%\%PROCESSNAME%\loggingErrors.log" ...

And to set those variables in code:

var logsDir = Environment.GetEnvironmentVariable(EnvVarLogsRoot, EnvironmentVariableTarget.Machine) ?? "Logs";
Environment.SetEnvironmentVariable(EnvVarLogsRoot, logsDir);