Solved

Enable environment variables in Log4Net file name value

Posted on 2010-09-17
6
1,389 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:beester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Corey2
ID: 33702525
Try using %USERNAME% I believe with log4net you have to use command line syntax for file name and path.
0
 
LVL 7

Author Comment

by:beester
ID: 33712215
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...
0
 
LVL 13

Accepted Solution

by:
Corey2 earned 500 total points
ID: 33713189
I recall running into an issue with this with the rolling log file appender I have been configuring it through code instead of  Settings.


            Dim apdr As New Appender.RollingFileAppender()
            Dim layout As New log4net.Layout.PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline")
            Dim Folder As String = My.Computer.FileSystem.SpecialDirectories.Temp
            With apdr
                .LockingModel = New log4net.Appender.RollingFileAppender.MinimalLock()
                .Name = "MyApplication Log"
                'Appears to be in bytes so this = 1mb
                .MaxFileSize = 1049000
                .AppendToFile = True
                .File = IO.Path.Combine(Folder, "MyApplication.log")
end with

Open in new window

0
 
LVL 7

Author Comment

by:beester
ID: 33765669
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...
0
 
LVL 13

Expert Comment

by:Corey2
ID: 33928589
Which version of log4net are you using?
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question