Log4net configuration of the WinForm project

Source: Internet
Author: User

Here's how:

One, app. config configuration

<?xml version="1.0"encoding="Utf-8"?><configuration> <configSections> <section name="log4net"Type="System.Configuration.IgnoreSectionHandler"/> </configSections> <startup> <supportedruntime version="v4.0"sku=". netframework,version=v4.5"/> </startup> <appSettings> <!--Compressed file decompression path--<add value="D:\FileCompare"key="Filecompare"/> </appSettings> <log4net> <appender name="Rollinglogfileappender"Type="log4net. Appender.rollingfileappender"> <param name="File"Value="Errorlogs\errorlog.txt"/> <param name="Appendtofile"Value="true"/> <param name="maxsizerollbackups"Value=" -"/> <param name="maximumFileSize"Value="8096KB"/> <param name="Rollingstyle"Value="Size"/> <param name="Staticlogfilename"Value="true"/> <layout type="log4net. Layout.patternlayout"> <!--<param name="Header"Value="[header]\r\n"/> <param name="Footer"Value="[footer]\r\n"/>--> <param name="Conversionpattern"Value="%d%-5p%c%m%n"/> </layout> </appender> <root> <level value=" All"/> <appender-ref ref="Rollinglogfileappender"/> </root> </log4net></configuration>

Second, call in Form.cs: Initialize log

Private void Btnselect_click (object  sender, EventArgs e)        {             = Logmanager.getlogger ("  Error");}

Three, Assmbely.cs configuration

?
1 2 3 4 //[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = "Log4Net.config")] // 日志组件配置 //[assembly: log4net.Config.DOMConfigurator(ConfigFile = "Log4Net.config", Watch = true)][assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)]

  

Don't forget to introduce Log4net.dll.

If the "app. Config hint error" configuration system failed to initialize "

Solution:

"If the configuration file contains a configsections element, the configsections element must be the first child element of the configuration element. "So if there is a connectionstrings or other node in front of it, you must put the connectionstrings behind it."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.