Hi Ron
>How are you initializing log4net in the applications that aren't
>logging correctly?


I config log4net in ClassLibrary or WinForm just like what in ConsoleApp in Visual Studio Team System 2005 Beta 2 :
1 AssemblyInfo.cs:[assembly: log4net.Config.XmlConfigurator(Watch = true)]
2 App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
        <configSections>
                <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
        </configSections>
        <appSettings>
                <!-- <add key="log4net.Internal.Debug" value="true"/> -->
        </appSettings>
        <log4net>
                <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
                        <file value="logs\DALTest-log-file.txt" />
                        <appendToFile value="true" />
                        <layout type="log4net.Layout.PatternLayout">
                                <conversionPattern value="%date [%thread] %-5level %logger -- %message%newline" />
                        </layout>
                </appender>
                <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
                        <layout type="log4net.Layout.PatternLayout">
                                <conversionPattern value="%date [%thread] %-5level %logger -- %message%newline" />
                        </layout>
                </appender>
                <root>
                        <level value="ALL" />
                        <appender-ref ref="LogFileAppender" />
                        <appender-ref ref="ConsoleAppender" />
                </root>
        </log4net>
</configuration>
3 Code in class:
using log4net;
...
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
...
logger.Debug("Test get-customer-list begins!");
...

I can't find config example in Class Library or WinForm.  Are there any differences with config for ConsoleApp?




Ron Grabowski <[EMAIL PROTECTED]>

02/16/2006 11:38 AM

Please respond to
"Log4NET User" <[email protected]>

To
Log4NET User <[email protected]>
cc
Subject
Re: How to log for a ClassLibrary project, but not a Console Application project?





Yes, log4net can be used with WinForm applications and Class Libraries.

How are you initializing log4net in the applications that aren't
logging correctly?

--- [EMAIL PROTECTED] wrote:

> Hi
> I have tried logging for Console Application project. It goes well.
> And I also tried logging in Class Library project (with code
> like"Logger.Debug("...");")  called by a Console Application project
> (with
> .config). This is allright too.
> But If I only applied log4net in a Class Library project, or a Class
> Library project called by a Windows Application project, it didn't
> run
> well.
> Can log4net  be applied to Windows Application? Class Library?
> How should I config it?
> Thanks in advance.
>
> Qiu-xia



Reply via email to