MVC log4net Configuration

Source: Internet
Author: User
Tags log4net

1. Quoting Log4net.dll

2. Add log4.config files under the project root directory

<?xml version="1.0"?><configuration> <configSections> <!--log4net configuration-<section name="log4net"Type="log4net. Config.log4netconfigurationsectionhandler,log4net"/> </configSections> <log4net debug="true"> <appender name="Rollinglogfileappender"Type="log4net. Appender.rollingfileappender"> <file value="Test.txt"/> <!--file You can specify a specific path Eg:d:\\test.log. If not specified, log is generated in the project's Bin/debug or Bin/release directory (the Web project is generated by default in the root directory)--<appendtofile value="true"/> <rollingstyle value="Size"/> <maxsizerollbackups value="Ten"/> <!--backup log files up to 10--<maximumfilesize value="2MB"/> <!--a maximum of 2M per log file, if more than 2M will recreate a new log file and back up the original log file. -<staticlogfilename value="true"/> <layout type="log4net. Layout.patternlayout"> <!--Specify log format--<conversionpattern value="[%date]%thread--%-5level--%logger [%M]--%message%newline"/> </layout> </appender> <root> <level value="DEBUG"/> <!--Specifies that logs of this level and above be printed to the log file--<appender-ref ref="Rollinglogfileappender"/> </root> </log4net></configuration>

3. Under AssemblyInfo.cs, add the following:

@" Log4net.config " true)]

4. Add the following code under Application_Start ():

Log4net. Config.XmlConfigurator.Configure (new FileInfo (Server.MapPath ("~/log4net.config" )));  // Read the log4net configuration file

5. Call directly in the project:

  ILog log = Logmanager.getlogger ("errormessage");                        Log. Error (Exception. ToString ());

MVC log4net Configuration

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.