阅读 84

log4net日志配置

//log4net日志
public static ILoggerRepository repository { get; set; }

public Startup(IConfiguration configuration)
{
Configuration = configuration;

repository = LogManager.CreateRepository("AprilLog");
XmlConfigurator.Configure(repository, new FileInfo("Config/log4net.config"));//配置文件路径可以自定义
BasicConfigurator.Configure(repository);
}

 

 

log4net.config文件配置

 

 













































































































































 

logUtil.cs类

 

using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace xiaowu.Common
{
///


/// 日志类
///

public class LogUtil
{

//https://www.cnblogs.com/AprilBlank/p/11282345.html
private static readonly ILog log = LogManager.GetLogger("AprilLog", typeof(LogUtil));

///


/// 调试日志
///

///
///
public static void Debug(string msg, object obj = null)
{
if (log.IsDebugEnabled && !string.IsNullOrEmpty(msg))
{
if (obj == null)
{
log.Debug(msg);
}
else
{
log.DebugFormat(msg, obj);
}
}
}
///
/// 日常日志
///

///
///
public static void Info(string msg, object obj = null)
{
if (log.IsInfoEnabled && !string.IsNullOrEmpty(msg))
{
if (obj == null)
{
log.Info(msg);
}
else
{
log.InfoFormat(msg, obj);
}
}
}
///
/// 错误日志
///

///
///
public static void Error(string msg, object obj = null)
{
if (log.IsErrorEnabled && !string.IsNullOrEmpty(msg))
{
if (obj == null)
{
log.Error(msg);
}
else
{
log.ErrorFormat(msg, obj);
}
}
}
///
/// 重要日志
///

///
///
public static void Fatal(string msg, object obj = null)
{
if (log.IsFatalEnabled && !string.IsNullOrEmpty(msg))
{
if (obj == null)
{
log.Fatal(msg);
}
else
{
log.FatalFormat(msg, obj);
}
}
}
}
}

 

原文:https://www.cnblogs.com/wugh8726254/p/15000226.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐