Log4Net not working when using config file

I would like to use log4net

in my current project.
So I started reading examples from the official documentation and played BasicConfigurator

around with a bit at first , but the next step would be going to the config file, not hardcoding.

I created a file XML

named MyApp.log4net

containing:

<log4net>
    <appender name="A1" 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="A1" />
    </root>
</log4net>

      

The config file is located in AppDomain.CurrentDomain.BaseDirectory

.

Then I added

[assembly: XmlConfigurator(ConfigFile = "MyApp.log4net", Watch = true)]
namespace Awesome.Server
{
    class Program
    {
        ...

      

to a class Program

that is in the same directory as MyApp.log4net

.
If I try to log in now, eg. using ...

LogManager.GetLogger(typeof(Program)).Info("Hello World");

      

... then nothing happens. No errors, no messages, nothing.
Is there anything I forgot / misunderstood about how this works to fix this?

+3


source to share


1 answer


You have specified the name of the configuration file as "Awesome.Server.log4net":

[assembly: XmlConfigurator(ConfigFile = "Awesome.Server.log4net", Watch = true)]
namespace Awesome.Server {
    ...
}

      



Either correct your config file name or change the build attribute property ConfigFile

.

+2


source







All Articles