using log4net;
using System;
using System.Diagnostics; namespace MxWeiXinPF.Common.log
{
public static class LogHelper
{
// private static LogMessage message = null; #region error 错误、异常时候记录日志 /// <summary>
/// 错误、异常时候记录日志
/// </summary>
/// <param name="message"></param>
public static void Error(object message)
{
LogManager.GetLogger(GetCurrentMethodFullName()).Error(message);
} /// <summary>
/// 错误、异常 记录日志
/// </summary>
/// <param name="message"></param>
/// <param name="exception"></param>
public static void Error(object message, Exception exception)
{
LogManager.GetLogger(GetCurrentMethodFullName()).Error(message, exception);
} /// <summary>
/// 错误、异常 记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Error(string message, int userid = , 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);
} /// <summary>
/// 错误、异常 记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Error(string message, Exception exception, int userid = , 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 请求,用户行为 记录日志 /// <summary>
/// 请求,用户行为 记录日志
/// </summary>
/// <param name="message"></param>
public static void Info(object message)
{
LogManager.GetLogger(GetCurrentMethodFullName()).Info(message);
} /// <summary>
/// 请求,用户行为 记录日志
/// </summary>
/// <param name="message"></param>
/// <param name="ex"></param>
public static void Info(object message, Exception ex)
{
LogManager.GetLogger(GetCurrentMethodFullName()).Info(message, ex);
} /// <summary>
/// 请求,用户行为 记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Info(string message, int userid = , 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);
} /// <summary>
/// 请求,用户行为 记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="ex">异常</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Info(string message, Exception ex, int userid = , 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 调试记录日志 /// <summary>
/// 调试记录日志
/// </summary>
/// <param name="message"></param>
public static void Debug(object message)
{ LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message); } /// <summary>
/// 调试记录日志
/// </summary>
/// <param name="message"></param>
/// <param name="ex"></param>
public static void Debug(object message, Exception ex)
{ LogManager.GetLogger(GetCurrentMethodFullName()).Debug(message, ex); } /// <summary>
/// 调试记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Debug(string message, int userid = , 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);
} /// <summary>
/// 错误、异常 记录日志
/// </summary>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
/// <param name="message">记录内容</param>
public static void Warn(string message, int userid = , 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);
} /// <summary>
/// 错误、异常 记录日志
/// </summary>
/// <param name="message">记录内容</param>
/// <param name="userid">userid</param>
/// <param name="platName">平台</param>
/// <param name="module">模块</param>
/// <param name="operating">操作行为</param>
/// <param name="flgValue">值</param>
/// <param name="addip">ip</param>
public static void Warn(string message, Exception exception, int userid = , 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 = ;
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(, exMessage.Length > ? : exMessage.Length); LogManager.GetLogger("内部调试").Error("GetCurrentMethodFullName()方法报错啦!!!", ex);
}
return MethodFullNameStr; // return "TestName";
}
}
}

log4net.config文件

<?xml version="1.0" encoding="utf-8"?>
<configuration> <configSections>
<section name="log4net" type="log4net.Config.log4NetConfigurationSectionHandler,log4net" />
</configSections> <log4net>
<!--数据库记录--> <!--错误日志-->
<appender name="ADONetAppenderMySqlClient" type="log4net.Appender.ADONetAppender">
<bufferSize value="" />
<param name="ReconnectOnError" value="true"/>
<connectionType value="MySql.Data.MySqlClient.MySqlConnection, MySql.Data" />
<connectionString value="server=10.1.0.228;user id=lijun;pwd=520777;port=3306;pooling=True;database=hurongclub_log;charset=utf8;" providerName="MySql.Data.MySqlClient;" />
<commandText value="INSERT INTO loginfo (ID,CreateTime,Thread,Level,Logger,Message,Exception,UserID,PlatName,Module,Operation,DeviceID,HRVersion,CustomerID,RequestUrl,RequestIPs) VALUES(@ID,@log_date,@thread,@log_level,@logger,@message,@exception,@UserID,@PlatName,@Module,@Operation,@DeviceID,@HRVersion,@CustomerID,@RequestUrl,@RequestIPs)" /> <!--logger4net-->
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter> <!--ID-->
<parameter>
<parameterName value="@ID" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{ID}" />
</layout>
</parameter>
<!--UserID -->
<parameter>
<parameterName value="@UserID" />
<dbType value="Int32" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{UserID}" />
</layout>
</parameter>
<!--PlatName -->
<parameter>
<parameterName value="@PlatName" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{PlatName}" />
</layout>
</parameter>
<!--Module -->
<parameter>
<parameterName value="@Module" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{Module}" />
</layout>
</parameter>
<!--Operation -->
<parameter>
<parameterName value="@Operation" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{Operation}" />
</layout>
</parameter>
<!--RequestIPs -->
<parameter>
<parameterName value="@RequestIPs" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{RequestIPs}" />
</layout>
</parameter>
<!--RequestUrl -->
<parameter>
<parameterName value="@RequestUrl" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{RequestUrl}" />
</layout>
</parameter>
<!--DeviceID -->
<parameter>
<parameterName value="@DeviceID" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{DeviceID}" />
</layout>
</parameter>
<!--HRVersion -->
<parameter>
<parameterName value="@HRVersion" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{HRVersion}" />
</layout>
</parameter>
<!--CustomerID -->
<parameter>
<parameterName value="@CustomerID" />
<dbType value="String" />
<size value="" />
<layout type="HuRongClub.Log.CustomLayout">
<conversionPattern value="%property{CustomerID}" />
</layout>
</parameter> <filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="ERROR" />
</filter>
</appender> <!--Txt记录形式--> <!--信息日志-->
<appender name="InfoRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile\Info\" />
<param name="AppendToFile" value="true" />
<param name="datePattern" value="yyyy-MM-dd.'Info.LOG'" />
<param name="staticLogFileName" value="false" />
<param name="rollingStyle" value="Composite" />
<param name="MaxSizeRollBackups" value="-1" />
<param name="MaximumFileSize" value="5000KB" /> <layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date -[%thread] %-5level -%logger %message %newline%newline" />
</layout> <filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="INFO" />
</filter>
</appender> <!--调试日志-->
<appender name="DebugRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile\Debug\" />
<param name="AppendToFile" value="true" />
<param name="datePattern" value="yyyy-MM-dd.'debug.LOG'" />
<param name="staticLogFileName" value="false" />
<param name="rollingStyle" value="Composite" />
<param name="MaxSizeRollBackups" value="-1" />
<param name="MaximumFileSize" value="5000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date -[%thread] %-5level -%logger %message %newline%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="DEBUG" />
</filter>
</appender> <!--警告日志-->
<appender name="WarningRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile\Warn\" />
<param name="AppendToFile" value="true" />
<param name="datePattern" value="yyyy-MM-dd.'warn.log'" />
<param name="staticLogFileName" value="false" />
<param name="rollingStyle" value="Composite" />
<param name="MaxSizeRollBackups" value="-1" />
<param name="MaximumFileSize" value="5000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%n记录时间:%date %n日志级别:%-5level %n日 志 类:%logger %n日志描述:%message %newline%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="WARN" />
<param name="LevelMax" value="WARN" />
</filter>
</appender> <!--错误日志-->
<appender name="ErrorRollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="logfile\Error\" />
<param name="AppendToFile" value="true" />
<param name="datePattern" value="yyyy-MM-dd.'error.LOG'" />
<param name="staticLogFileName" value="false" />
<param name="rollingStyle" value="Composite" />
<param name="MaxSizeRollBackups" value="-1" />
<param name="MaximumFileSize" value="5000KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%n记录时间:%date %n日志级别:%-5level %n日 志 类:%logger %n日志描述:%message %newline%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="Error" />
<param name="LevelMax" value="ERROR" />
</filter>
</appender> <root>
<level value="All" />
<!--数据库 形式记录日志-->
<!--<appender-ref ref="ADONetAppenderMySqlClient" />--> <!--文件形式记录日志-->
<appender-ref ref="ErrorRollingFileAppender" />
<appender-ref ref="DebugRollingFileAppender" />
<appender-ref ref="WarningRollingFileAppender" />
<appender-ref ref="InfoRollingFileAppender" />
</root>
</log4net> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

asp.net 的log4net的helper类的更多相关文章

  1. 一点ASP.NET MVC Html.Helper类的方法

    一点ASP.NET MVC Html.Helper类 这里就只写一个Html.ActionLink()和Html.DropdownList(). Html.ActionLink()里有三个参数,第一个 ...

  2. MVC中使用HTML Helper类扩展HTML控件

    文章摘自:http://www.cnblogs.com/zhangziqiu/archive/2009/03/18/1415005.html MVC在view页面,经常需要用到很多封装好的HTML控件 ...

  3. ASP.NET Core MVC – Tag Helper 组件

    ASP.NET Core Tag Helpers系列目录,这是第五篇,共五篇: ASP.NET Core MVC – Tag Helpers 介绍 ASP.NET Core MVC – Caching ...

  4. Asp.net Core + Log4net + ELK 搭建日志中心

    原文:Asp.net Core + Log4net + ELK 搭建日志中心 Docker中一键安装ELK 对于这种工具类的东西,第一步就直接到docker的hub中查找了,很幸运,不仅有Elasti ...

  5. .NET中的加密算法总结(自定义加密Helper类续)

    1.1.1 摘要 相信许多人都使用过.NET提供的加密算法,而且在使用的过程我们必须了解每种加密算法的特点(对称或非对称,密钥长度和初始化向量等等).我也看到过很多人写过.NET中加密算法总结,但我发 ...

  6. 之前采用的是Helper类的方法重构时改用了扩展方法

    在手机端输入网址不方全,通常会将网址做成一个二维码,然后用手机扫一下就可以打开预览.我们每改一下样式,就在手机上点一下刷新或电脑上按一下F5,这在最初的时候,也不觉得有什么问题,因为拿到我手上的静态页 ...

  7. Task的在主线程处理异常信息的Helper类

    最近使用task时候需要把异常记录日志,直接注入非单例模式的实例进入异步线程,在高并发情况下会出现一些问题. 所以需要把异常反馈给主线程 ,并且不在主线程里进行等待,研究相关资料后,自己写了一个简单的 ...

  8. Util和Helper类

    Util和Helper Util Util类,应该是一个无状态的类,只有静态方法. 比如在获取某些类的全局实例化对象的时候可以使用. public class ParamUtil { ... publ ...

  9. 基于log4net的帮助类Log

    using log4net; using System; using System.Collections.Generic; using System.Diagnostics; using Syste ...

随机推荐

  1. MTU是什么?

    MTU是Maximum Transmission Unit的缩写. 意思是网络上传送的最大数据包. MTU的单位是字节. 大部分网络设备的MTU都是1500.如果本机的MTU比网关的MTU大,大的数据 ...

  2. X509Store 类

    标题:X509Store 类 地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.x509certi ...

  3. excel打开提示 文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?

    有的时候打开xls文档时,会提示“文件格式和扩展名不匹配.文件可能已损坏或不安全.除非您信任其来源,否则请勿打开.是否仍要打开它?” 遇到这种情况,我们需要 打开“注册表编辑器” win键+R键,打开 ...

  4. alpha冲刺事后诸葛亮(团队)

    alpha冲刺事后诸葛亮(团队) 课程名称:软件工程1916|W(福州大学) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标:完成Alpha冲刺的事后诸葛亮 团队队员 队员学号 ...

  5. 项目Beta冲刺--2/7

    项目Beta冲刺--2/7 作业要求 这个作业属于哪个课程 软件工程1916-W(福州大学) 这个作业要求在哪里 项目Beta冲刺 团队名称 基于云的胜利冲锋队 项目名称 云评:高校学生成绩综合评估及 ...

  6. Tomcat热部署和热加载

    1.热部署与热加载 在应用运行的时候升级软件,无需重新启动的方式有两种,热部署和热加载.它们之间的区别是: (1).部署方式: 热部署在服务器运行时重新部署项目.热加载在运行时重新加载class. ( ...

  7. postman:设置环境变量(参数化 & 关联)

    postman是测试接口的主要工具之一 我们的测试环境主要分为test(测试环境)和pre_production(预生产环境),而他们的api都是一样的,只是ip及端口不一样 所以,我们可以设置环境变 ...

  8. 【Javascript】call

    var ShowDlg = function ShowDlg() { } ShowDlg.prototype.animate = function(msg) { alert(msg); } var l ...

  9. list转json数组

    lights为arraylist java后台代码: try {      org.tempuri.TLight[] lights = phlightSoapProxy.getLights();    ...

  10. Word中同样行间距,同样字号,同样字体,但是肉眼看起来行距不一样

    感谢博主转载:https://blog.csdn.net/hongweigg/article/details/47130009 困扰了我好久,直接上解决办法: 然后选择 自定义页边距 选择 无网络(N ...