网上现在有关 .Net 6中使用Nlog的文章还没有,之前使用的是ASP .Net Core3。在框架中使用了Nlog写日志。本篇文章主要介绍.net 3/5中和.net 6中使用nlog有何不同。相比.net 3/5中,新的.net6的 Program中更加简单了,不再默认把一些配置写入Startup中了。
关于net core3/5中使用Nlog可参考我之前写的文章:https://lebang2020.cn/details/201218judpn4f2.html
下面主要说一下它们之间的不同:
net core3/5
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config)=>
{
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
}).UseNLog();
net 6中我们这样使用:
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
{
}).ConfigureLogging(logging =>
{
logging.ClearProviders();
}).UseNLog();