I have a .net dll configured as a web service running under IIS. I added log4Net logging and did the below setup under Assembylnfo
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "bin\log4net.config", Watch = true)]
After that, i enabled the log4net diagnostics using the below in web.config
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="E:\MyLocation\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
<system.serviceModel>
Used the below section to create an instance of logger.
private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Now i get the below entries along with a lot of the diagnostics information in my log4net.txt which shows initialisation if fine and it is able to open the log file
log4net: configuring repository [MYRepository] using file [E:\MyLocation\bin\log4net.config] watching for file updates
log4net: Opening file for writing [...]
At this point i am able to get the logs correctly. Now after the logs for initialisation of above, i get the below lines towards the bottom
log4net: configuring repository [MYRepository] using .config file section
log4net: Application config file is [E:\MyLocation\web.config]
log4net:ERROR Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
If the initialisation was successful as in in the top part of the log, why is log4net trying to check web.config for the configuration again in web.config?
<add key="log4net.Internal.Debug" value="true"/>
inapp.config
? Actually, you are trying to do the different things,[assembly: log4net.Config.XmlConfigurator(ConfigFile = "bin\log4net.config", Watch = true)]
here you are configuring logs for your application,system.diagnostics
enables the log4net internal debugging to monitor the problems of log4net itself – Pavel Anikhouski