.NetCore WebApi 添加 Log4Net
2021-06-09 17:03
标签:control tin append http att manager read set star 一 、配置 1.vs2019 创建一个.net core web程序,选择webapi 2.项目中添加一个配置文件:添加--新建项--XML文件,命名为log4net.config 我使用的是log4net的RollingLogFileAppender,他的好处是按天记录日志,一般日志记录会选择30天 更多选项参考:http://logging.apache.org/log4net/release/config-examples.html 3.startup配置 public static ILoggerRepository repository { get; set; } public Startup(IConfiguration configuration) Configuration = configuration; repository = LogManager.CreateRepository("NETCoreRepository"); 二、应用 public class ValuesController : ControllerBase private log4net.ILog log = log4net.LogManager.GetLogger(Startup.repository.Name, typeof(ValuesController)); public ActionResult } .NetCore WebApi 添加 Log4Net 标签:control tin append http att manager read set star 原文地址:https://www.cnblogs.com/blog-zhaof/p/10655759.html
{
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
}
{
{
log.Info($"ValuesController-Get id:{id}");
return "value";
}
文章标题:.NetCore WebApi 添加 Log4Net
文章链接:http://soscw.com/index.php/essay/92759.html