12345678910111213141516171819202122232425262728293031323334353637 |
- using log4net.Config;
-
- using System;
- using System.IO;
-
- namespace Common.system
- {
- public class LogHelper
- {
- public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
- public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
-
- public static void InitLog4Net()
- {
- var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
- XmlConfigurator.ConfigureAndWatch(logCfg);
- loginfo.Info("日志初始化");
- }
-
- public static void WriteInfoLog(string info)
- {
- if (loginfo.IsInfoEnabled)
- {
- loginfo.Info(info);
- Console.WriteLine(info);
- }
- }
-
- public static void WriteErrLog(string info, Exception ex)
- {
- if (logerror.IsErrorEnabled)
- {
- logerror.Error("[V " + FileToolsCommon.GetConfigValue("VersionName") + "]" + info, ex);
- }
- }
- }
- }
|