You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Qi...@sybase.com on 2006/02/16 03:48:47 UTC

How to log for a ClassLibrary project, but not a Console Application project?

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

Re: How to log for a ClassLibrary project, but not a Console Application project?

Posted by Ron Grabowski <ro...@yahoo.com>.
According to this page:

http://tinyurl.com/cajh5
http://logging.apache.org/log4net/release/manual/configuration.html#dot-config

you should probably be using Log4NetConfigurationSectionHandler instead
of IgnoreSectionHandler.

Class libraries usually don't have any log4net initialize code in them.
The top most layer application (usually the UI layer or website) starts
the log4net initialize process.

This link describes strategies for debugging log4net during its startup
process:

http://logging.apache.org/log4net/release/faq.html#internalDebug

--- Qiu-xia.Zhang@sybase.com wrote:

> 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>

[snip]

Re: How to log for a ClassLibrary project, but not a Console Application project?

Posted by Qi...@sybase.com.
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 <ro...@yahoo.com> 
02/16/2006 11:38 AM
Please respond to
"Log4NET User" <lo...@logging.apache.org>


To
Log4NET User <lo...@logging.apache.org>
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?

--- Qiu-xia.Zhang@sybase.com 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




Re: How to log for a ClassLibrary project, but not a Console Application project?

Posted by Ron Grabowski <ro...@yahoo.com>.
Yes, log4net can be used with WinForm applications and Class Libraries.

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

--- Qiu-xia.Zhang@sybase.com 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