?
Solved

dynamic log file name with log4net

Posted on 2010-11-23
3
Medium Priority
?
3,746 Views
Last Modified: 2013-12-17
I am using log4net to log information, errors and warnings while running my console ETL application in C#.

I am generating a new log file daily (so the file name just consist of the date)

however due to change in requirements I am now required to dynamically generate a new log (which is a combination of Filename to be extracted and Datetime)

I tried changing my currently log4net settings in the App.config file without much success.

Here is my new log4net settings that tries to generate a new log file for each extract

<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
     <param name="File" value="\\\\NetworkPath\\Logs\\%property{LogName}"/>
     <param name="AppendToFile" value="true"/>
     <rollingStyle value="Size" />
     <maxSizeRollBackups value="-1" />
     <maximumFileSize value="5000KB" />
     <countDirection value="1"/>
     <layout type="log4net.Layout.PatternLayout">
       <param name="Header" value="[Header]\r\n"/>
       <param name="Footer" value="[Footer]\r\n"/>
       <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %u %c %l %m %n"/>
     </layout>
     <filter type="log4net.Filter.PropertyFilter">
       <Key value="Version" />
       <StringToMatch value="1" />
     </filter>
     <filter type="log4net.Filter.DenyAllFilter" />
   </appender>

*** original code replaced by thermoduric at askers request {http://www.experts-exchange.com/Q_27105761.html}.

and in the actual c# file i try to implement the log file is as follows

                foreach (var file in files)
                {
                    //GlobalContext.Properties["LogName"] = config.Source + " - " + config.SqlMappingCode + ".log";
                    GlobalContext.Properties["LogName"] = "test.log";
                    var _log = LogManager.GetLogger(typeof(Program));
                    XmlConfigurator.Configure();
                    _log.Info("Start Processing FX Rates feed...");
                    csvImporter.LoadData(fxRatesConfig, JobType.FXRates);
                }

However this code just results in the following file name

%property{LogName}

Can anyone please tell me how i can achieve the dynamic log file?
0
Comment
Question by:2ooth
[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
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
buraksarica earned 2000 total points
ID: 34195397
Check this blog post : http://geekswithblogs.net/rgupta/archive/2009/03/03/dynamic-log-filenames-with-log4net.aspx

It seems that you are working with wrong type of Appender.
0
 
LVL 5

Expert Comment

by:buraksarica
ID: 34203208
Is it working?
0
 

Author Comment

by:2ooth
ID: 34203919
Yes it is working!!!!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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