0
votes

i'm developing a simple .NET application and i'm tryng to use log4Net to log some usefull info. With the basic configuration i have no problem. When i try to use an xml configuration i have the following problem:

log4net:ERROR Error while loading XML configuration System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at log4net.Config.XmlConfigurator.InternalConfigure(ILoggerRepository repository, Stream configStream)

The piece of code is the following:

var xmlConfig = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location+path.DirectorySeparatorChar+"logConfig.xml");
if (xmlConfig != null) XmlConfigurator.Configure(new FileInfo(xmlConfig));
else BasicConfigurator.Configure();

The xml file is taked directly from log4net documentation and is the following

<log4net>
    <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="INFO" />
        <appender-ref ref="ConsoleAppender" />
    </root>
</log4net>

how can i solve that error, i think the xml is correct assuming there is no error in documentation.

1
Check your XML for nonprintable characters, stackoverflow.com/questions/291455/…CodeCaster
I just figured out myself. Wrong parentesis on Get directory name, i will post an autoanswer Asap!Razlo3p

1 Answers

0
votes

Solved, i just typed wrong a parentesis. I will answer this for community

var xmlConfig = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + "logConfig.xml";