I'm getting an error on a program that has log4net configured, but no log file is being created. I'm certain the logging is set up in the program because other users have created log files from the same, using an identical config file to what I'm posting below (except for the filepath). I'm sure that I have write permissions to the path. At the point where the program fails, it absolutely must have passed the initialization of the logging.
Does anything look wrong in this config file, or has anybody experienced a similar issue and know something I should look for within the program I'm trying to get a log from?
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="AutoTag" type="System.Configuration.NameValueSectionHandler"/> <section name="WindwardReports" type="System.Configuration.NameValueSectionHandler"/> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/> </configSections> <AutoTag> <add key="_debug" value="true"/> </AutoTag> <WindwardReports> <add key="line.break" value="internal"/> </WindwardReports> <appSettings> <add key="sql.timeout" value="240"/> </appSettings> <log4net> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="C:\Users\loganm\Documents\Catapult.log"/> <param name="AppendToFile" value="true"/> <param name="MaxSizeRollBackups" value="2"/> <param name="MaximumFileSize" value="100KB"/> <param name="RollingStyle" value="Size"/> <param name="StaticLogFileName" value="true"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] ac.server %-5p %c - %m%n"/> </layout> </appender> <root> <level value="DEBUG"/> <appender-ref ref="RollingFileAppender"/> </root> </log4net> </configuration>
In your case, the log file will be in bin\Debug\netcoreapp3.
log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.
Log4net watches for any new file created in the folder so simply creating the . log4net configuration file triggers the update within the component that is logging. When using a file appender, the destination folder does not have to exist. Log4net creates the folder.
Give the following code in your application before you put your logging code:
log4net.Config.XmlConfigurator.Configure();
You can define it in Global.asax:
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup // Initialize log4net. log4net.Config.XmlConfigurator.Configure(); }
You can also add the following line as Kevin advised (either mentioning your config file name or not):
[assembly: log4net.Config.XmlConfigurator]
or
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Web.config", Watch = true)]
Hope it helps!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With