| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using log4net;
- using log4net.Config;
- namespace StressClient.common
- {
- public static class LogHelper
- {
- //private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()?.DeclaringType);
- //static LogHelper()
- //{
- // XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));
- // // var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");
- // //Log = LogManager.GetLogger(typeof(LogHelper));
- //}
- /// <summary>
- /// 记录调试信息
- /// </summary>
- /// <param name="ex">信息</param>
- public static void Debug(this Object obj, object message)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Debug(message);
- }
- /// <summary>
- /// 记录警告信息
- /// </summary>
- /// <param name="ex">信息</param>
- public static void Warn(this Object obj, object message)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Warn(message);
- }
- /// <summary>
- /// 记录错误信息
- /// </summary>
- /// <param name="ex">信息</param>
- public static void Error(this Object obj, object message)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Error(message);
- }
- /// <summary>
- /// 记录重要提示信息
- /// </summary>
- /// <param name="ex">信息</param>
- public static void Info(this Object obj,object message)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Info(message);
- }
- /// <summary>
- /// 记录信息和异常信息
- /// </summary>
- /// <param name="message">错误信息</param>
- /// <param name="ex">异常对象</param>
- public static void Debug(this Object obj,object message, Exception ex)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Debug(message, ex);
- }
- /// <summary>
- /// 记录信息和异常信息
- /// </summary>
- /// <param name="message">错误信息</param>
- /// <param name="ex">异常对象</param>
- public static void Warn(this Object obj, object message, Exception ex)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Warn(message, ex);
- }
- /// <summary>
- /// 记录信息和异常信息
- /// </summary>
- /// <param name="message">错误信息</param>
- /// <param name="ex">异常对象</param>
- public static void Error(this Object obj, object message, Exception ex)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Error(message, ex);
- }
- /// <summary>
- /// 记录信息和异常信息
- /// </summary>
- /// <param name="message">错误信息</param>
- /// <param name="ex">异常对象</param>
- public static void Info(this Object obj, object message, Exception ex)
- {
- ILog Log = LogManager.GetLogger(obj.GetType());
- Log.Info(message, ex);
- }
- }
- }
|