Link to home
Start Free TrialLog in
Avatar of beester
beesterFlag for Norway

asked on

Enable environment variables in Log4Net file name value

I'm wondering why I can't seem to use environment variables in the following settings in a .config file for a .net application:

<appender name="RollingLogFile" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="..\\Logg\\Dashboard\\logfilename.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="3"/>
      <param name="MaximumFileSize" value="5MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <param name="CountDirection" value="-1"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/>
      </layout>

Open in new window


If I try to use i.e. ${USERNAME}.log it only creates a new file with the filename ${USERNAME}.log instead of a username.

What is the correct syntax/variable to use for this, if possible at all?

This is a Windows environment
Avatar of Corey Scheich
Corey Scheich
Flag of United States of America image

Try using %USERNAME% I believe with log4net you have to use command line syntax for file name and path.
Avatar of beester

ASKER

Nope, doesn't seem to help. Tried ${%USERNAME%}, env{%USERNAME%}, {%USERNAME%} and just %USERNAME%, and all it does is to create a log file with the name as I write it, it doesn't parse the environment variables...
ASKER CERTIFIED SOLUTION
Avatar of Corey Scheich
Corey Scheich
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beester

ASKER

I checked with our head programmer, and he said that this wasn't a viable solution for us. But he also said he thought this was solved in a newer Log4Net than the one we use, so I guess I'll try upgrading first...
Which version of log4net are you using?