-----Original Message-----
From: Nicko Cadell [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 21, 2004 10:03 AM
To: Log4NET User
Subject: RE: New User question - configuration file format
Mike,
If you have the option you should use the 1.2 beta 8 version as this
issue is fixed in that version. This version fixes a number of issues in
the library.
If you have to use 1.1.1 then you can use the Configure method that
accepts an XmlElement. You can find the log4net element by doing the
following:
// Load the config
XmlDocument doc = new XmlDocument();
doc.Load(configFile);
// Select the log4net element
XmlNodeList configNodeList = doc.GetElementsByTagName("log4net");
// Copy into root of new document
XmlDocument newDoc = new XmlDocument();
XmlElement newElement =
(XmlElement)newDoc.AppendChild(newDoc.ImportNode(configNodeList[0],
true));
// Call configure
DOMConfigurator.Configure(newElement);
Cheers,
Nicko
> -----Original Message-----
> From: Mike Van De Vijsel [mailto:[EMAIL PROTECTED]
> Sent: 20 December 2004 21:12
> To: '[email protected]'
> Subject: New User question - configuration file format
>
> Hi there,
>
> I'm using log4net version 1.1.1 in a .dll assembly using
> VB.NET. I'm simply trying to get a ConsoleAppender to work
> with my configuration file. For some reason, if I have the
> log4net configuration information in its own .config file,
> log4net seems to read it properly. If, however, I have it
> included with other configuration information in the same
> file, it doesn't read it and no logging occurs. I assume this
> is possible because the log4net site
> says:
>
> "The configuration is read from the log4net element in the
> file. Only one log4net element can be specified in the file
> but it may be located anywhere in the XML hierarchy."
>
> Some details: My class is called NAMEndpoint. I have my class
> configuring log4net as follows:
>
> Private Shared ReadOnly mobjLogMgr As ILog =
> LogManager.GetLogger(GetType(NAMEndpoint))
>
> In the New method of this class:
>
> DOMConfigurator.Configure(New System.IO.FileInfo(strConfigPath))
>
> Where strConfigPath is the path of the configuration file. My
> own custom code is correctly reading this file using the same
> variable so I'm sure the file path is correct and valid.
>
> My configuration file looks like:
>
> <?xml version="1.0" ?>
> <NAMEndpoint>
> <log4net debug="true">
> <appender name="ConsoleAppender"
> type="log4net.Appender.ConsoleAppender" >
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%date
> [%thread] %-5level %logger [%ndc] - %message%newline" />
> </layout>
> </appender>
> <root>
> <level value="DEBUG" />
> <appender-ref ref="ConsoleAppender" />
> </root>
> </log4net>
> <systemID>1</systemID>
> <filePath>Z:\Datafaction Phase II\New Messages from NAM
> Website</filePath> </NAMEndpoint>
>
> The SystemID and filePath elements at the bottom are separate
> configurations I've set up.
>
> If I take the <log4net> node out of this file and put it in
> its own file, it seems to work OK, and the internal debugging
> information gets generated. But with the file the way it is
> above, I get no errors when calling
> DOMConfigurator.Configure, but when I try and log a message I get:
>
> log4net:ERROR No appenders could be found for category
> (LoringWard.Integration.NAMEndpoint).
> log4net:ERROR Please initialize the log4net system properly.
>
> I assume it's not finding the configuration information
> properly. What am I doing wrong?
>
> Any pointers or help you can provide would be great.
>
> Thanks,
>
> Mike van de Vijsel
> [EMAIL PROTECTED]
>