标签:
记入最基本的用法 :
refer : http://www.cnblogs.com/aehyok/archive/2013/05/07/3066010.html
<configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> </configuration>
<configuration> <log4net debug="true"> <!--ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF--> <root> <level value="debug" /> <appender-ref ref="LogFileAppender" /> <appender-ref ref="SmtpAppender" /> </root> <logger name="Loggering"> <!--<level value="debug"/> <appender-ref ref="LogFileAppender"/>--> </logger> <appender name="LogFileAppender" type="log4net.Appender.FileAppender" > <param name="File" value="D:\Google Drive\learn\LogForNet\LogForNet\log\log.txt" /> <param name="AppendToFile" value="true" /> <layout type="log4net.Layout.PatternLayout"> <!--输出内容控制--> <!--<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />--> <param name="ConversionPattern" value="%d %-5p: %m%n" /> </layout> </appender> <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <authentication value="Basic" /> <to value="hengkeat87@gmail.com" /> <from value="stooges@stooges.com.my" /> <username value="stooges@stooges.com.my" /> <password value="I(..." /> <subject value="程序异常日志记录邮件发送" /> <smtpHost value="mail.stooges.com.my" /> <enableSsl value="false" /> <port value="587" /> <bufferSize value="512" /> <lossy value="true" /> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="error"/> <!--拦截error而已--> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" /> </layout> </appender> </log4net> </configuration>
void Application_Start(object sender, EventArgs e) { log4net.Config.XmlConfigurator.Configure(); // Code that runs on application startup AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); }
public class HomeController : Controller { private static readonly ILog log = LogManager.GetLogger("Loggering"); // GET: Home public ActionResult Index() { try { log.Info("log日志信息"); log.Debug("debug信息"); //log.Error("error信息"); //log.Warn("warn信息"); //Exception ex = new Exception("测试的异常信息"); //log.Fatal("fatal信息", ex); } catch (Exception ex) { throw; } return View(); } }
标签:
原文地址:http://www.cnblogs.com/keatkeat/p/5437344.html