asp.net core3.1 log4net 整合
2021-04-02 14:27
标签:returns pre name dex ram epo time array you 第一步: NuGet管理安装log4net组件。 第二步:添加log4net.config配置文件 第三步:定义一个配置,添加一个类UseLog4netApplicationBuilder.cs 第四步: Startup.cs添加Configure 第六步: Controller里面使用 第七步: 查看日志, 找到你定义的路径,打开log文件 asp.net core3.1 log4net 整合 标签:returns pre name dex ram epo time array you 原文地址:https://www.cnblogs.com/whtydn/p/12552120.htmlxml version="1.0" encoding="utf-8" ?>
log4net>
root>
level value="DEBUG"/>
appender-ref ref="SysAppender"/>
appender-ref ref="consoleApp"/>
root>
appender name="SysAppender" type="log4net.Appender.RollingFileAppender">
param name="File" value="D:\\Logs\\" />
param name="AppendToFile" value="true" />
param name="MaximumFileSize" value="20MB" />
param name="MaxSizeRollBackups" value="100" />
param name="StaticLogFileName" value="false" />
param name="DatePattern" value="\\yyyyMM\\yyyyMMdd".log"" />
param name="RollingStyle" value="Composite" />
layout type="log4net.Layout.PatternLayout">
param name="ConversionPattern" value="%n
--------------------------------------------------------------------------------------
%n日志时间:%d [%t] %n日志级别:%-5p %n日 志 类:%c [%x] %n%m %n" />
param name="Header" value="
======================================================================================
" />
layout>
appender>
appender name="consoleApp" type="log4net.Appender.ConsoleAppender,log4net">
layout type="log4net.Layout.PatternLayout,log4net">
param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
layout>
appender>
logger name="WebLogger">
level value="DEBUG"/>
logger>
log4net>
public static class UseLog4netApplicationBuilder
{
///
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseLog4net(); //这里是添加的
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILog log;
public WeatherForecastController(ILogger
======================================================================================
--------------------------------------------------------------------------------------
日志时间:2020-03-23 14:38:20,372 [9]
日志级别:ERROR
日 志 类:AspNetCoreApp.Controllers.WeatherForecastController [(null)]
Error 90000: Error Error Error Error Error Error Error Error!
--------------------------------------------------------------------------------------
日志时间:2020-03-23 14:38:20,394 [9]
日志级别:INFO
日 志 类:AspNetCoreApp.Controllers.WeatherForecastController [(null)]
Info 10000: Info Info Info Info Info Info Info Info Info Info Info Info Info Info!
--------------------------------------------------------------------------------------
日志时间:2020-03-23 14:38:20,395 [9]
日志级别:WARN
日 志 类:AspNetCoreApp.Controllers.WeatherForecastController [(null)]
Warn 20000: Warn Warn Warn Warn Warn Warn Warn Warn Warn Warn Warn Warn Warn Warn!
上一篇:jsp变量和方法的声明
下一篇:收藏的一些实用网站
文章标题:asp.net core3.1 log4net 整合
文章链接:http://soscw.com/index.php/essay/71420.html