Reputation: 1092
i try to include log4net in my project and have quite weird problem.
My looks like below:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
<section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
and later in webconfig have:
<log4net>
(...)
</log4net>
Log4net doesn't work-file with errors isn't being created.
Now when i changed on purpose config section for "microsoft.identityModel" (did some typo) and tried to go on my website -there is error. But when i changed on purpose config section for "log4net" - website works well-looks like
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
is skipped or doesn't matter. Any ideas what i'm doing wrong?
Upvotes: 1
Views: 124
Reputation: 17724
Put this in your Global.asax file:
void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
}
You need to to tell log4net how it should configure itself somewhere. Global.asax is a good place for this.
Upvotes: 0
Reputation: 1039498
Make sure you have initialized your logger in Application_Start
:
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
...
}
or use the assembly level attribute as illustrated in the documentation:
[assembly: log4net.Config.XmlConfigurator()]
Upvotes: 3