123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using log4net;
- using System.IO;
- namespace Logs
- {
- public class LogHelper
- {
- static LogHelper()
- {
- string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\logconfig.xml";
- log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
- }
- /// <summary>
- /// 接口
- /// </summary>
- private static ILog __GetLog(Object obj)
- {
- string name = string.Empty;
- if (obj.GetType().Name == "String")
- {
- name = obj.ToString();
- }
- else
- {
- name = obj.GetType().Name;
- }
-
-
- return log4net.LogManager.GetLogger(name);
- }
- /// <summary>
- /// 调试
- /// </summary>
- /// <param name=”message”>消息</param>
- public static void Debug(string message)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsDebugEnabled)
- log.Debug(message);
- }
- public static void Debug(Object obj, string message)
- {
- ILog log = __GetLog(obj);
- if (log.IsDebugEnabled)
- __GetLog(obj).Debug(message);
- }
- /// <summary>
- /// 调试
- /// </summary>
- /// <param name=”message”>消息</param>
- /// <param name=”exception”>异常</param>
- public static void Debug(string message, Exception ex)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsDebugEnabled)
- log.Debug(message, ex);
- }
- public static void Debug(Object obj, string message, Exception ex)
- {
- ILog log = __GetLog(obj);
- if (log.IsDebugEnabled)
- __GetLog(obj).Debug(message, ex);
- }
- /// <summary>
- /// 信息
- /// </summary>
- /// <param name=”message”>消息</param>
- public static void Info(string message)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsInfoEnabled)
- log.Info(message);
- }
- /// <summary>
- /// 信息
- /// </summary>
- /// <param name=”message”>消息</param>
- /// <param name=”exception”>异常</param>
- public static void Info(string message, Exception ex)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsInfoEnabled)
- log.Info(message, ex);
- }
- /// <summary>
- /// 一般错误
- /// </summary>
- /// <param name=”message”>消息</param>
- public static void Error(string message)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsErrorEnabled)
- log.Error(message);
- }
- /// <summary>
- /// 一般错误
- /// </summary>
- /// <param name=”message”>消息</param>
- /// <param name=”exception”>异常</param>
- public static void Error(string message, Exception exception)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsErrorEnabled)
- log.Error(message, exception);
- }
- /// <summary>
- /// 警告
- /// </summary>
- /// <param name=”message”>消息</param>
- public static void Warn(string message)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsWarnEnabled)
- log.Warn(message);
- }
- /// <summary>
- /// 警告
- /// </summary>
- /// <param name=”message”>消息</param>
- /// <param name=”exception”>异常</param>
- public static void Warn(string message, Exception ex)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsWarnEnabled)
- log.Warn(message, ex);
- }
- /// <summary>
- /// 严重
- /// </summary>
- /// <param name=”message”>消息</param>
- public static void Fatal(string message)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsFatalEnabled)
- log.Fatal(message);
- }
- /// <summary>
- /// 严重
- /// </summary>
- /// <param name=”message”>消息</param>
- /// <param name=”exception”>异常</param>
- public static void Fatal(string message, Exception ex)
- {
- ILog log = __GetLog(string.Empty);
- if (log.IsFatalEnabled)
- log.Fatal(message, ex);
- }
- }
- }
|