123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using log4net;
- using log4net.Config;
- using System;
- using System.Diagnostics;
- using System.IO;
- namespace AIRS
- {
- /// <summary>
- /// function:Log
- /// author :lbf
- /// date :2020/6/17 17:31:13
- /// </summary>
- /// <summary>
- /// 使用Log4net插件的log日志对象
- /// </summary>
- public static class Log
- {
- private static ILog log;
-
- static Log()
- {
- XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
- log = LogManager.GetLogger(typeof(Log));
- }
- private static string getTraceMessage(object message)
- {
- var traceInfo = new StackTrace();
- return string.Format("[{0}-{1}] {2}", traceInfo.GetFrame(2).GetMethod().ReflectedType.Name, traceInfo.GetFrame(2).GetMethod().Name, message);
- }
- public static void Debug(object message)
- {
- log.Debug(getTraceMessage( message));
- }
- public static void DebugFormatted(string format, params object[] args)
- {
- log.DebugFormat(format, args);
- }
- public static void Info(object message)
- {
- log.Info(getTraceMessage(message));
- }
- public static void InfoFormatted(string format, params object[] args)
- {
- log.InfoFormat(format, args);
- }
- public static void Warn(object message)
- {
- log.Warn(getTraceMessage(message));
- }
- public static void Warn(object message, Exception exception)
- {
- log.Warn(getTraceMessage(message), exception);
- }
- public static void WarnFormatted(string format, params object[] args)
- {
- log.WarnFormat(format, args);
- }
- public static void Error(object message)
- {
- log.Error(getTraceMessage(message));
- }
- public static void Error(object message, Exception exception)
- {
- log.Error(message, exception);
- }
- public static void ErrorFormatted(string format, params object[] args)
- {
- log.ErrorFormat(format, args);
- }
- public static void Fatal(object message)
- {
- log.Fatal(getTraceMessage(message));
- }
- public static void Fatal(object message, Exception exception)
- {
- log.Fatal(getTraceMessage(message), exception);
- }
- public static void FatalFormatted(string format, params object[] args)
- {
- log.FatalFormat(format, args);
- }
- }
- }
|