Configure the log in the framework in 2 steps, one is to create a new log class in the Help project Zy.utilities--zy.utility.core, encapsulate the Write log method, and also need to add log4net references in Zy.Utility.Core
1. Log Implementation class
1[Assembly:log4net. Config.xmlconfigurator (Watch =true)] 2 namespaceZy.Utility.Core3 { 4 /// <summary> 5 ///Log Processing Class6 /// </summary> 7 Public Static classLog8 { 9 Public Static voidError (stringmsg)Ten { OneLog4net. ILog log =log4net. Logmanager.getlogger (msg); A log. Error (msg); - } - the Public Static voidInfo (stringmsg) - { -Log4net. ILog log =log4net. Logmanager.getlogger (msg); - log. Info (msg); + } - + Public Static voidWarning (stringmsg) A { atLog4net. ILog log =log4net. Logmanager.getlogger (msg); - log. Warn (msg); - } - - Public Static voidError (stringmsg, Exception ex) - { inLog4net. ILog log =log4net. Logmanager.getlogger (msg); -Log. Error ("Error", ex); to } + - Public Static voidInfo (stringmsg, Exception ex) the { *Log4net. ILog log =log4net. Logmanager.getlogger (msg); $Log. Info ("Info", ex); Panax Notoginseng } - the Public Static voidWarning (stringmsg, Exception ex) + { ALog4net. ILog log =log4net. Logmanager.getlogger (msg); theLog. Warn ("Warning", ex); + } - } $}
View Code
2, configure the LOG4 in Web. config of the project, after the configuration, start the project will generate a log folder in the Zycommon-zyweb project
1<log4net>2<!--data Log--3<appender name="Inforollingfileappender"Type="log4net. Appender.rollingfileappender">4<lockingmodel type="log4net. Appender.fileappender+minimallock"/>5<param name="File"Value="log\info\ "/>6<param name="Appendtofile"Value="true"/>7<param name="Rollingstyle"Value="Date"/>8<param name="Datepattern"Value="yyyy-mm-dd. ' Info.log '"/>9<param name="Staticlogfilename"Value="false"/>Ten<layout type="log4net. Layout.patternlayout"> One<conversionpattern value="%n%n%n record time:%date%n log level:%-5level%n Error class:%logger%n error Description:%message %newline%newline"/> A</layout> -<filter type="log4net. Filter.levelrangefilter"> -<param name="Levelmin"Value="INFO"/> the<param name="Levelmax"Value="INFO"/> -</filter> -</appender> -<!--error log-- +<appender name="Errorrollingfileappender"Type="log4net. Appender.rollingfileappender"> -<lockingmodel type="log4net. Appender.fileappender+minimallock"/> +<param name="File"Value="log\error\ "/> A<param name="Appendtofile"Value="true"/> at<param name="Rollingstyle"Value="Date"/> -<param name="Datepattern"Value="yyyy-mm-dd. ' Error.log '"/> -<param name="Staticlogfilename"Value="false"/> -<layout type="log4net. Layout.patternlayout"> -<conversionpattern value="%n%n%n record time:%date%n log level:%-5level%n Error class:%logger%n error Description:%message %newline%newline"/> -</layout> in<filter type="log4net. Filter.levelrangefilter"> -<param name="Levelmin"Value="ERROR"/> to<param name="Levelmax"Value="ERROR"/> +</filter> -</appender> the<!--Debug Logs-- *<appender name="Debugrollingfileappender"Type="log4net. Appender.rollingfileappender"> $<lockingmodel type="log4net. Appender.fileappender+minimallock"/>Panax Notoginseng<param name="File"Value="log\debug\ "/> -<param name="Appendtofile"Value="true"/> the<param name="Rollingstyle"Value="Date"/> +<param name="Datepattern"Value="yyyy-mm-dd. ' Debug.log '"/> A<param name="Staticlogfilename"Value="false"/> the<layout type="log4net. Layout.patternlayout"> +<conversionpattern value="%n%n%n record time:%date%n log level:%-5level%n Error class:%logger%n error Description:%message %newline%newline"/> -</layout> $<filter type="log4net. Filter.levelrangefilter"> $<param name="Levelmin"Value="DEBUG"/> -<param name="Levelmax"Value="DEBUG"/> -</filter> the</appender> -<root>Wuyi<level value="DEBUG"/> the< log in as!--file- -<appender-ref ref="Errorrollingfileappender"/> Wu<appender-ref ref="Debugrollingfileappender"/> -<appender-ref ref="Inforollingfileappender"/> About</root> $</log4net>
View Code
Log folder is divided into debug, error, info folder, respectively, write the error level of different logging information
Errors in development, error messages will be written to the error folder, according to the configuration rules generated a TXT folder every day, debugging can also be written to the log
Write the C # MVC framework from scratch---Configure the LOG4 log