yzh
2022-06-23 203edd6bbdf883e897a0075037a4ef68cd519ac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
using log4net;
using log4net.Config;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
 
namespace Common
{
  public abstract class LogHelper
  {
    private static ILog _LogAll = LogManager.GetLogger("LOGALL");
    private static ILog _LogErr = LogManager.GetLogger("LOGERR");
    private static ILog _LogDebug = LogManager.GetLogger("LOGDEBUG");
 
    private static string GetMethodName(StackTrace trace)
    {
      MethodBase method = trace.GetFrame(1).GetMethod();
      return (method.ReflectedType.Module.Name + " " + method.ReflectedType.Name + "." + method.Name).PadRight(50);
    }
 
    public static void Config(string configFile)
    {
      XmlConfigurator.ConfigureAndWatch(new FileInfo(configFile));
    }
 
    public static void Error(string format, params object[] args)
    {
      LogHelper._LogErr.Error((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args)));
    }
 
    public static void Info(string format, params object[] args)
    {
      LogHelper._LogAll.Info((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args)));
    }
 
    public static void Warn(string format, params object[] args)
    {
      LogHelper._LogAll.Warn((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args)));
    }
 
    public static void Debug(string format, params object[] args)
    {
      LogHelper._LogDebug.Debug((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args)));
    }
 
    public static void Fatal(string format, params object[] args)
    {
      LogHelper._LogErr.Fatal((object) string.Format("{0} {1}", (object) LogHelper.GetMethodName(new StackTrace()), (object) string.Format(format, args)));
    }
 
    public static void Error(Exception e)
    {
      LogHelper._LogErr.Error((object) string.Format("{0} {1}\r\n{2}", (object) LogHelper.GetMethodName(new StackTrace()), (object) e.Message, (object) e.StackTrace));
    }
  }
}