log4net是Net平台下老牌日志组件,logdashboard完全适配log4net,但由于log4net不支持在Net Core将日志写到数据库,所以logdashboard并不推荐使用log4net做为最佳实践
Install-Package Microsoft.Extensions.Logging.Log4Net.AspNetCore
loggerFactory.AddLog4Net(new Log4NetProviderOptions
{
PropertyOverrides =
new List<NodeInfo>
{
new NodeInfo { XPath = "/log4net/appender/file[last()]", Attributes = new Dictionary<string, string> { { "value", $"{AppContext.BaseDirectory}LogFiles/" } } }
}
});
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="LogFiles/"/>
<preserveLogFileNameExtension value="true" />
<datePattern value="yyyy-MM-dd'.log'" />
<staticLogFileName value="false"/>
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date || %5level || %logger || %message || %exception ||end %newline" />
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFile" />
</root>
</log4net>
Install-Package LogDashboard
public void ConfigureServices(IServiceCollection services)
{
services.AddLogDashboard();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseLogDashboard();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}