Log4net usage Summary-(2) use in ASP. net mvc, log4netmvc

Source: Internet
Author: User
Tags log4net

Log4net usage Summary-(2) use in ASP. net mvc, log4netmvc
Log4net configuration in ASP. net mvc, there is also a configuration method, that is, not in web. config, but to create a separate log4net. config under the root directory1. Reference log4net. dll 2. Add log4net. config under the root directory of the site

<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <configSections> <section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/> </configSections> <log4net> <! -- Define output to file --> <appender name = "RollingLogFileAppender" type = "log4net. Appender. RollingFileAppender"> <! -- Define the file storage location --> <file value = "log \"/> <appendToFile value = "true"/> <rollingStyle value = "Date"/> <datePattern value = "yyyy-MM-dd'.txt '"/> <staticLogFileName value = "false"/> <param name = "MaxSizeRollBackups" value = "100"/> <param name = "Encoding" value = "UTF-8 "/> <layout type =" log4net. layout. patternLayout "> <! -- <ConversionPattern value = "% newline % n record time: % date % n thread ID: [% thread] % n log level: %-5 level % n error class: % logger property: [% property {NDC}]-% n error Description: % message % newline % n "/> --> <conversionPattern value =" % newline % nDate: % date % nThread: [% thread] % nLevel: %-5 level % nClass: % logger [% property {NDC}] % nMessage: % message % newline "/> </layout> </appender> <root> <level value =" ALL "/> <! -- Log in the file format --> <appender-ref = "RollingLogFileAppender"/> </root> </log4net> </configuration>

  

3. Configure xmlConfigurationAdd [assembly: log4net. Config. XmlConfigurator (ConfigFile = "log4net. config", ConfigFileExtension = "config", Watch = true)] to AssemblyInfo under site properties. Fourth, write test in the console as work
public class HomeController : Controller    {        log4net.ILog log = log4net.LogManager.GetLogger(typeof(HomeController));        public ActionResult Index()        {            log.Info("test....");                 return View();        }}

  

Related Article

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.