日期:2014-05-18 浏览次数:21142 次
public static class Logger { private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public static void Debug(object message) { if (logger.IsDebugEnabled) { logger.Debug(message); } }
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net debug="true"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="c:\test.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="2KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <footer value="[Footer]--Test By cxy1981 " /> <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" /> </layout> </appender> <root> <priority value="ALL" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> </configuration>
public class Logger { public static bool GetTracerSwitchor() { string configPath = Application.StartupPath + "\\eSerialPro.exe"; System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configPath); bool IsTracer = Convert.ToBoolean(config.AppSettings.Settings["IsTracer"].Value); return IsTracer; } /// <summary> /// 调试信息 /// </summary> /// <param name="msg"></param> public static void Debug(string msg) { bool IsTracer = GetTracerSwitchor(); if (IsTracer) { log4net.ILog log = log4net.LogManager.GetLogger("Test"); if (log.IsDebugEnabled) { log.Debug(msg); } log = null; } } }
------解决方案--------------------
------解决方案--------------------
命名空间前加上[assembly: log4net.Config.XmlConfigurator(Watch = true)]
------解决方案--------------------
WEB的不是很明白,只能帮顶了。
------解决方案--------------------
学习
------解决方案--------------------
没用过...纯顶支持
------解决方案--------------------