I would like to use log4net
in my current project.
So I started to read examples from the official documentation and first played a bit with the BasicConfigurator
but the next step is to switch to a configuration file instead of hardcoding everything.
I created a XML
file called 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
.
Next I added
[assembly: XmlConfigurator(ConfigFile = "MyApp.log4net", Watch = true)]
namespace Awesome.Server
{
class Program
{
...
to the Program
class which is located in the same directory as MyApp.log4net
.
If I now try to log someting e.g. using...
LogManager.GetLogger(typeof(Program)).Info("Hello World");
...then nothing happens. No error, no message, nothing.
Is there anything I forgot/misunderstood about how this works that would fix this?
You specified the configuration file's name to be "Awesome.Server.log4net":
Either fix your config file name or change the assembly attribute property
ConfigFile
.