博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# log4net配置
阅读量:3711 次
发布时间:2019-05-21

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

1.通过管理NuGet程序包 引入log4net.dll程序集

管理NuGet程序包 引入log4net.dll程序集
2.配置log4netConfig.xml文件

3.新建公共方法类Log4NetHelper

public class Log4NetHelper    {
private static readonly ILog Loginfo = LogManager.GetLogger("InfoLog"); private static readonly ILog Logwarn = LogManager.GetLogger("Warn"); private static readonly ILog Logerror = LogManager.GetLogger("ErrorLog"); private static readonly ILog Logfatal = LogManager.GetLogger("Fatal"); static Log4NetHelper() {
var configFile = HostingEnvironment.MapPath("/App_Data/Log4netConfig.xml"); log4net.Config.XmlConfigurator.Configure(new FileInfo(configFile)); //log4net.Config.XmlConfigurator.Configure(); } private static string GetMethodInfo() {
StackTrace ss = new StackTrace(true); //index:0为本身的方法;1为调用方法;2为其上上层,依次类推 MethodBase mb = ss.GetFrame(2).GetMethod(); string systemModule = $"{Environment.NewLine}模块名:{mb.Module}{Environment.NewLine}命名空间名:{mb.DeclaringType?.Namespace}{Environment.NewLine}类名:{mb.DeclaringType?.Name}{Environment.NewLine}方法名:{mb.Name}"; return systemModule; } public static void Info(string msg) {
Loginfo.Info($"{GetMethodInfo()}——{msg}"); } public static void Error(string msg) {
Logerror.Error($"{GetMethodInfo()}——{msg}"); } } }

转载地址:http://zacjn.baihongyu.com/

你可能感兴趣的文章
springboot2.0 解决前后端跨域问题
查看>>
基于SSM框架实现的项目——绿色蔬果商城
查看>>
基于SSM框架实现的项目——绿色蔬果商城后台
查看>>
基于springboot+mybatis+vue+elementUI实现的网欲音乐系统
查看>>
springboot+vue实现滑块验证登入
查看>>
使用shiro实现多Realm认证——用户名密码、手机短信验证
查看>>
基于springboot+shiro阿里云短信服务实现短信验证登入
查看>>
非常好使的客户端redis工具Another Redis Desktop Manager
查看>>
一款基于 Spring Boot 2.1.0 、 Jpa、 Spring Security、redis、Vue 的前后端分离的后台管理系统
查看>>
Spring boot整合JWT实现登入认证
查看>>
使用requests模块爬取豆瓣电影top50数据
查看>>
邮件(email)
查看>>
SVN的使用与简介
查看>>
Servlet3.0实现注解开发
查看>>
java中《自定义注解》的使用
查看>>
软件开发的流程
查看>>
对JDBC驱动注册--DriverManager.registerDriver和 Class.forName()的理解
查看>>
node.js系统模块fs的fs.feadFile方法读取不到文件 [Error: no such file or directory]
查看>>
【JavaScript】拖动事件,鼠标拖动元素出现默认样式原因及解决方法,进度条拖动样式,拖动对象dataTransfer对象
查看>>
【node.js】第三方模块joi报错 UnhandledPromiseRejectionWarning: TypeError: Joi.validate is not a function
查看>>