Unrecognized configuration section log4net
26,950
Solution 1
You need to declare the log4net
section:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
Take a closer look at the documentation
which explains the necessary things to do.
Solution 2
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
</configuration>
add to your app.config file
Author by
Shreyas Achar
Updated on July 09, 2022Comments
-
Shreyas Achar almost 2 years
I have this code in web.config:
<log4net> <root> <level value="ALL" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="D:\logFileFaculty.txt" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> </log4net>
And I have downloaded
log4net.dll
and placed it inBin
Folder.In one of My
aspx.cs
pages I have added this code:using log4net; [assembly: log4net.Config.XmlConfigurator(Watch = true)] private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
But it's giving error as
Unrecognized configuration section log4net
. -
Perry Tew almost 8 yearsBeing an utter noob at C#, I followed the instructions (almost) by opening the app.config file, finding another <section> element, and pasting the log4net one right above. it. I didn't realize at first that I had pasted it inside a <sectionGroup> tag. That didn't work. So I finally realized my mistake and pasted it directly inside the <configSections> element. 20 minutes of my life chalked up to haste and carelessness.