if its a seperate dll, you just need to add [assembly : log4net.Config.XmlConfigurator(Watch=true)], but the application you use needs to have the appropriate xml structure in their app config.

if you want it to work regardless of if the referencing application has log4net configured, you can configure it to log by hand (and I think thats documented, though I cant point you to where off hand).

--steve

Maybhate, Dipty wrote:

Thanks Steve

I want the log4net to initialize in Class libraries. In my understanding I would need to create like a log4net.config or some file like that and mention that in AssemblyInfo.cs

if it should be done in class libraries.

 

Basically I have created a Logger class in the class library project and reference it in ASP.net project in the same solution by creating its constructor in Page_Load of the home page

When the constructor is called it goes to the log4net code

private static readonly ILog logger =

                  LogManager.GetLogger(typeof(Class1));

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("App.config"));

                  logger.Debug("Here is a debug log.");

                  logger.Info("... and an Info log.");

                  logger.Warn("... and a warning.");

                  logger.Error("... and an error.");

                  logger.Fatal("... and a fatal error.");

 

but doesn’t create a log file

I hope this makes some sense

I have wasted like 2 days and also didn’t have much time to read anything on this

Thanks again!

Dipty

 


From: Steve Whitley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 16, 2006 12:41 PM
To: Log4NET User
Subject: Re: FW: Problem logging in class library

 

asp.net's config is called web.config.  try looking for that.

Maybhate, Dipty wrote:

 

 


From: Maybhate, Dipty
Sent: Wednesday, August 16, 2006 10:55 AM
To: '[email protected]'
Subject: Problem logging in class library

 

Hi Everyone

I am new to log4net and I am facing problems with it. In my .Net solution I have a class library project and a ASP.net project. I want to create a Logger class which is like a wrapper in the class library and have all the other Webservices or ASP.net projects in the solution access that.

This is how I use log4net in the Class library

 

AssemblyInfo.cs

[assembly : log4net.Config.XmlConfigurator(Watch=true)]

 

App.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <configSections>

        <section name="log4net"

           type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

    </configSections>

    <log4net>

        <appender name="FileAppender" type="log4net.Appender.FileAppender">

            <param name="File" value="c:\\LogTest23.txt" />

            <param name="AppendToFile" value="true" />

            <layout type="log4net.Layout.PatternLayout">

                <param name="Header" value="[Header]\r\n" />

                <param name="Footer" value="[Footer]\r\n" />

                <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />

            </layout>

        </appender>               

        <root>

            <level value="INFO" />

            <appender-ref ref="FileAppender" />            

        </root>

    </log4net>

</configuration>

 

Logger class

private static readonly ILog logger =

                  LogManager.GetLogger(typeof(Class1));

log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("App.config"));

                  logger.Debug("Here is a debug log.");

                  logger.Info("... and an Info log.");

                  logger.Warn("... and a warning.");

                  logger.Error("... and an error.");

                  logger.Fatal("... and a fatal error.");

 

I also tried using the <ClassLibraryName>.exe.config as the name for the app.config as I read it somewhere

Then my ASP.net application creates an object of this Class1 from the class library application and see if the log file is created

Could you please help me figure out what I am doing wrong?

Thank you very much

Dipty

 

 

 


Reply via email to