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 |
|
Paul Santa Maria
 |
| 10/23/2008 2:52 AM |
|
Hi -
1. I'm using C# and Visual Studio 2008
2. I created a minimal C# that invokes log4net:
using log4net; using log4net.Config; ... public class DeleteLogs2 { private static readonly ILog logger = LogManager.GetLogger (typeof (DeleteLogs2)); static void Main (string[] args) { log4net.Util.LogLog.InternalDebugging = true; logger.Info ("Hello world"); ...
3. I have a minimal log4net.xml file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="FileAppender" /> <appender-ref ref="ConsoleAppender" /> </root> <appender name="FileAppender" type="log4net.Appender.RollingFileAppender" > <file value="test-out.log" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value=".yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{MM/dd/yy HH:mm:ss.SSS} [%C.%M] %-5p %m%n" /> </layout> </appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" > <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%C.%M] %-5p %m%n" /> </layout> </appender> </log4net> </configuration>
4. I downloaded and installed Log4net 1.2.10 (log4net.dll, from log4net-1.2.10\bin\net\2.0\release). I copied log4net.dll and my log4net.xml into my VS2008 project directory I added a reference to log4net.dll. It compiled without error. VS2008 automagically copied my log4net.xml and log4net.dll into the debug directory, along with TestLog.exe
5. I step through under the VS2008 debugger: I don't see anything written to the console, nor do I get a log file.
6. The only internal debugging output occurs *after* the last line (i.e. during program exit): "log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]"
Does anybody have any ideas?
| |
|
|
|
|
Ron Grabowski
 |
| 10/23/2008 3:12 AM |
|
Your log4net.xml configuration should just contain just the log4net node:
<?xml version="1.0" encoding="utf-8" ?> <log4net> <root> <level value="DEBUG" /> <appender-ref ref="ConsoleAppender" /> </root> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" > <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%C.%M] %-5p %m%n" /> </layout> </appender> </log4net>
You have to start log4net by calling one of the Configure methods:
static void Main (string[] args) { XmlConfigurator.Configure(new FileInfo("log4net.xml")); logger.Info ("Hello world"); }
|
|
|
|
|
Paul Santa Maria
 |
| 10/23/2008 7:08 AM |
|
|
Thank you very much - adding the line you suggested fixed the problem:
XmlConfigurator.Configure(new System.IO.FileInfo("log4net.xml"));: | |
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|