博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
asp.net 的log4net的helper类
阅读量:4840 次
发布时间:2019-06-11

本文共 11810 字,大约阅读时间需要 39 分钟。

using log4net;using System;using System.Diagnostics;namespace MxWeiXinPF.Common.log{    public static class LogHelper    {        // private static LogMessage message = null;        #region error 错误、异常时候记录日志        ///         /// 错误、异常时候记录日志        ///         ///         public static void Error(object message)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Error(message);        }        ///         /// 错误、异常 记录日志        ///         ///         ///         public static void Error(object message, Exception exception)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Error(message, exception);        }        ///         /// 错误、异常 记录日志        ///         /// 记录内容        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Error(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Error(lm);        }        ///         /// 错误、异常 记录日志        ///         /// 记录内容        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Error(string message, Exception exception, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Error(lm, exception);        }        #endregion        #region info 请求,用户行为  记录日志        ///         /// 请求,用户行为  记录日志        ///         ///         public static void Info(object message)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Info(message);        }        ///         /// 请求,用户行为  记录日志        ///         ///         ///         public static void Info(object message, Exception ex)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Info(message, ex);        }        ///         /// 请求,用户行为  记录日志        ///         /// 记录内容        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Info(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Info(lm);        }        ///         /// 请求,用户行为  记录日志        ///         /// 记录内容        /// 异常        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Info(string message, Exception ex, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Info(lm, ex);        }        #endregion        #region debug 调试记录日志        ///         /// 调试记录日志        ///         ///         public static void Debug(object message)        {                           LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message);                    }        ///         ///  调试记录日志        ///         ///         ///         public static void Debug(object message, Exception ex)        {                            LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message, ex);                     }        ///         /// 调试记录日志        ///         /// 记录内容        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Debug(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {                           LogMessage lm = new LogMessage();                lm.userid = userid;                lm.platName = platName;                lm.module = module;                lm.operating = operating;                lm.flgValue = flgValue;                lm.addip = Utils.getIPAddress();                lm.remark = message;                LogManager.GetLogger(GetCurrentMethodFullName()).Debug(lm);                     }        #endregion        #region warin 警告        public static void Warn(object message)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message);        }        public static void Warn(object message, Exception ex)        {            LogManager.GetLogger(GetCurrentMethodFullName()).Warn(message, ex);        }        ///         /// 错误、异常 记录日志        ///         /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        /// 记录内容        public static void Warn(string message, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Warn(lm);        }        ///         /// 错误、异常 记录日志        ///         ///  记录内容        /// userid        /// 平台        /// 模块        /// 操作行为        /// 值        /// ip        public static void Warn(string message, Exception exception, int userid = 0, string platName = "", string module = "", string operating = "", string flgValue = "")        {            LogMessage lm = new LogMessage();            lm.userid = userid;            lm.platName = platName;            lm.module = module;            lm.operating = operating;            lm.flgValue = flgValue;            lm.addip = Utils.getIPAddress();            lm.remark = message;            LogManager.GetLogger(GetCurrentMethodFullName()).Warn(lm, exception);        }        #endregion        private static string GetCurrentMethodFullName()        {            StackFrame frame;            string MethodFunStr = "";            string MethodFullNameStr = "";            // bool flag;            try            {                int num = 2;                StackTrace stackTrace = new StackTrace();                int length = stackTrace.GetFrames().Length;                //do                //{
int num1 = num; // num = num1 + 1; frame = stackTrace.GetFrame(num1); MethodFunStr = frame.GetMethod().DeclaringType.ToString(); // flag = (!MethodFunStr.EndsWith("Exception") ? false : num < length); //} //while (flag); string name = frame.GetMethod().Name; MethodFullNameStr = string.Concat(MethodFunStr, ".", name); } catch (Exception ex) { string exMessage = ex.Message; MethodFullNameStr = exMessage.Substring(0, exMessage.Length > 200 ? 200 : exMessage.Length); LogManager.GetLogger("内部调试").Error("GetCurrentMethodFullName()方法报错啦!!!", ex); } return MethodFullNameStr; // return "TestName"; } }}

log4net.config文件

 

转载于:https://www.cnblogs.com/puzi0315/p/11318568.html

你可能感兴趣的文章
asp.net 的log4net的helper类
查看>>
shell编程
查看>>
2018上IEC计算机高级语言(C)作业 第1次作业
查看>>
hdu 1753
查看>>
return ;
查看>>
td在relative模式下,IE9不显示border
查看>>
7-内置数据结构
查看>>
version control(版本控制)
查看>>
FutureTask
查看>>
JDBC的元数据
查看>>
Intel CPU参数查询网站
查看>>
JQuery - Ajax和Tomcat跨域请求问题解决方法!
查看>>
spring跨重定向传递数据
查看>>
10693 PKKJ的生日礼物
查看>>
把Nehe 纹理教程06,用freeImage改写
查看>>
python 中is和= = 的区别
查看>>
[C/C++]关于C++11中的std::move和std::forward
查看>>
图片显示、PNG透明
查看>>
Java的sql动态参数
查看>>
centos 6.5 双网卡 上网 virtualbox nat hostonly
查看>>