I have a project in which I want to use log.net
for logging. When I'm testing my project using a console app program, it does not log anything unless I write the log.net
section in the app.config
of the test project. How do i fix this?
This is my configuration in my app.config
file in the DLL:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="MyLogFile.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{ABSOLUTE} [%thread] %level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value ="DEBUG"/>
<appender-ref ref ="RollingFileAppender"/>
</root>
</log4net>
From log.net
documentation page: https://logging.apache.org/log.net/release/manual/configuration.html ( Configuration Files section)
The only way to configure an application using the System.Configuration APIs is to call the log.net.Config.XmlConfigurator.Configure() method or the log.net.Config.XmlConfigurator.Configure(ILoggerRepository) method.
Make sure you are initializing log.net on your console app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.