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.
| Author |
Messages |
|
Milind Lad
 |
| 08/25/2008 7:05 AM |
|
Hi All,
I am new to log4net. I would to integrate this dll into my application. So I have done the following steps: 1. I have added log4net dll into my application. 2. Then insert this code protected static readonly ILog objLog = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private showLog() { if (objLog.IsDebugEnabled) objLog.Error("While save"); }
I hope these are the only steps to integrate log4net into application. But on load I get IsDebugEnabled FALSE. So it is difficult to write log.
Please help me!!
Thanks in advance
Regards, Milind Lad.
|
|
|
|
|
Dean Fiala
 |
| 08/25/2008 1:17 PM |
|
You need to configure log4net for the application first. To tell it what to log and where to log it.
http://logging.apache.org/log4net/release/manual/configuration.html
The XmlConfigurator lets you use an XML file to set up the appenders you want to use. It can also be set up to automaticall change your log settings when the file is updated. Very handy.
HTH,
Dean
|
|
|
|
|
Walden H. Leverich
 |
| 08/25/2008 3:31 PM |
|
As Dean pointed out, check that you're actually starting log4net. Also though, in your example you're checking if the Debug level is enabled, but you're logging an error. While this isn't "wrong" per-se, it's not common. I would expect that you'd check Debug if you were logging debug, and check Error if you were logging error. Then again, you may be doing something slightly different.
-Walden
-- Walden H Leverich III Tech Software (516) 627-3800 x3051 WaldenL@TechSoftInc.com http://www.TechSoftInc.com
Quiquid latine dictum sit altum viditur. (Whatever is said in Latin seems profound.)
|
|
|
|
|
Daniel Williams
 |
| 08/25/2008 3:51 PM |
|
Also, you need to configure the logging system. A simple way to do it is to put this into your assemblyinfo.cs file:
[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch = true)]
Then make an actual config file called log4net.config and make sure it's in your app's working folder. There are many examples out on the web. Here is one that will output to the console if you're running the app from there:
<?xml version="1.0" encoding="utf-8" ?> <configuration>
<configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections>
<log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" > <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p [%x] - %m%n" /> </layout> </appender>
<root> <level value="ALL" /> <appender-ref ref="ConsoleAppender" /> </root> </log4net>
</configuration>
Cheers, Daniel Williams
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|