log4 Configuration

netCore log4 Configuration

. 1  ///  <Summary> 
2      /// using LOG4NET logging functions, to be configured in WEB.CONFIG in the respective nodes
 . 3      ///  </ Summary> 
. 4      public  class LogHelper
 . 5      {
 . 6          // log4net dedicated log 
. 7  
. 8          Private  static ILoggerRepository Repository = LogManager.CreateRepository ( " AgentRepository " );
 . 9  
10          Private  static the ILog loginfo;
 . 11          Private  static the ILog logError;
 12 is          public LogHelper ()
 13 is          {
14         }
15         public static void SetConfig()
16         {
17             XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
18             Loginfo = LogManager.GetLogger(repository.Name, "loginfo");
19             Logerror = LogManager.GetLogger(repository.Name, "logerror");
20         }
21 
22         public static void SetConfig(FileInfo configFile)
23         {
24             log4net.Config.XmlConfigurator.Configure(repository, configFile);
25         }
26         /// <summary>
27         /// 普通的文件记录日志
28         /// </summary>
29         /// <param name="info"></param>
30         public static void WriteLog(string info)
31         {
32             SetConfig();
33             if (Loginfo.IsInfoEnabled)
34             {
35                 Loginfo.Info(info);
36             }
37         }
38         /// <summary>
39         /// 错误日志
40         /// </summary>
41         /// <param name="info"></param>
42         /// <param name="se"></param>
43         public static void WriteLog(string info, Exception se)
44         {
45             SetConfig();
46             if (Logerror.IsErrorEnabled)
47             {
48                 Logerror.Error(info, se);
49             }
50         }
51 
52     }

 

Guess you like

Origin www.cnblogs.com/lostsea/p/11573216.html