Showing posts with label log4net. Show all posts
Showing posts with label log4net. Show all posts
Tuesday, 29 October 2019
Tuesday, 5 March 2019
.net core console adding log4net
Log4Net will not use the log settings in the appsetting.json file, it needs a log4net.config file ðŸ˜
- add package
- add Log4Net into the logging framework
Tuesday, 6 February 2018
Configuring Log4net
reference:
https://stackoverflow.com/questions/10204171/configure-log4net-in-web-application
Add the nuget package:

Stick this line somewhere:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
(like the AssemblyInfo.cs file, or just cram it at the top of your controller like a madman - but only include it once)
Configure web.config settings:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="RollingLog.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
Get a reference to the logger
private static readonly ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Go crazy logging things


Output looks like

Subscribe to:
Posts (Atom)







