This article only say the main points, download and so on the Internet to search.
First step: Compiling Log4net.dll into the framework 4.0
Step two: Find the AssemblyInfo under the project's properties. Add at the bottom: [Assembly:log4net. Config.xmlconfigurator (Watch = True)].
Step three: Web. config
<configuration> <configSections> <section name="log4net"Type="System.Configuration.IgnoreSectionHandler"/> </configSections> <log4net> <appender name="Logfileappender"Type="log4net. Appender.rollingfileappender"> <file value="logs/"/> <appendtofile value="true"/> <rollingstyle value="Date"/> <datepattern value="Yyyy-mm-dd.txt"/> <staticlogfilename value="false"/> <layout type="log4net. Layout.patternlayout"> <conversionpattern value="%date Threadid:[%thread] Log level:%-5level class:%logger desp:%message%newline"/> </layout> </appender> <root> <appender-ref ref="Logfileappender"/> </root> </log4net></cconfiguration>
Fourth Step: Global.asax Applicatin_start method Add: ILog log = Logmanager.getlogger (Methodbase.getcurrentmethod (). DeclaringType);
has been completed, here is the call:
Logmanager.getlogger (Methodbase.getcurrentmethod (). DeclaringType). Error ("Logtest");
The calling method is not professional, just for demonstration purposes. Can be encapsulated for invocation.
MVC4 under Configuration log4net