Recently i had an issue making Log4Net work (described here) but after that it was OK.
I have left this behind a while because i needed to develop some modules and i left the logging somewhat behind. Now that i look, i have even tried changing the name of the log file and the location (set it statically), it is creating it but not writing anything to it in both cases.
This is my log4Net config file:
<?xml version="1.0"?>
<configuration>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
<appender name="console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message%newline" />
</layout>
</appender>
<appender name="file" type="log4net.Appender.RollingFileAppender">
<file value="ApplicationLogging.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
This is my Global.asax
[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
XmlConfigurator.Configure();
ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
logger.Info("Application started.");
How i declare it:
readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
I than use it sometimes like this:
logger.Info("some logging here");
Or for Context logging i would use it like this:
context.Database.Log = (dbLog => logger.Debug(dbLog));
The file is created, but no content is written to it. Can anyone suggest me where or what to look for?
UPDATE: As suggested by stuartd i have added this in the web.config:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>
Which writes the following content (pastebin)
Note that i have removed the first section which i didn't saw before and i think it is redundant?
<!--<appender name="console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %level %logger - %message%newline" />
</layout>
</appender>-->
Either way with or without it it doesn't work.
Here is the output WITH the first part NOT commented out (in its original state)
I tried the following as well: https://logging.apache.org/log4net/release/config-examples.html https://csharp.today/log4net-tutorial-great-library-for-logging/
I am clueless on why it can create it but not write to it... I can not seem to find anything on the web neither, all issues are regarding the creation of the file, not writing to it.