Monday, May 21, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: How to use separate config file for log4net
Prev Next
You are not authorized to post a reply.

Author Messages
wijitha

12/05/2008 4:46 PM  


Hi all

I want to use log4net with my project.
here is the simple example i tried.

App.config :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
       <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

  </configSections>

  <log4net>
     A1 is set to be a ConsoleAppender
    <appender name="A1" type="log4net.Appender.ConsoleAppender">

       A1 uses PatternLayout
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%-4timestamp [%thread] %-5level %logger
%ndc - %message%newline" />
      </layout>
    </appender>

     Set root logger level to DEBUG and its only appender to A1
    <root>
      <level value="DEBUG" />
      <appender-ref ref="A1" />
    </root>
  </log4net>
  </configuration>

here is the code:

        private static readonly ILog log =
LogManager.GetLogger(typeof(Program));
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            log.Info("Entering application.");
            log.Debug("Exiting application.");
            Console.Write("This Log4Net example");
        }

This thing is working well.
And what i want to do is put the log4net configuration part in a separate
file call Log4Net.config

if any one know how to do this please reply me. It is better if u can
separately give me the two configuration files. (App.config and
Log4Net.config)

thanks a lot
wijitha

--
View this message in context: http://www.nabble.com/How-to-use-separate-config-file-for-log4net-tp20856712p20856712.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Michael Schall

12/05/2008 7:14 PM  
You don't need anything in your app.config.  Just use the log4net.Config.XmlConfigurator.ConfigureAndWatch method instead as pass it a file with your log4net definitions.

Log4Net.config:
<log4net>
    ...
    <root>
        ...
    </root>
</log4net>

This will also allow you to change logging settings while the program is running.

Mike
 
jsinnott@sftcon.com

12/05/2008 9:04 PM  

// initialize the log4net config file

// the system expects to find it in the same folder as the exe file = /bin/debug

FileInfo log4NetConfigFile = new FileInfo("MyCustomConfigFile.config");

if (log4NetConfigFile == null || ! log4NetConfigFile.Exists) throw new Exception("unable to find log4net log file");

XmlConfigurator.Configure(log4NetConfigFile);

 

Michael Schall

12/06/2008 3:19 PM  

No, it is only required once for the process.

Sent from my iPod

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > How to use separate config file for log4net



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement