如何在Kestrel项目中使用useserilog
我有此引导代码,并且正在尝试核算如何将Serilog添加到其中。
using Microsoft.AspNetCore.Components.WebAssembly.Server ;
using System.Net;
using Serilog;
using Serilog.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Configure the HTTP request pipeline.
if (builder.Environment.IsDevelopment()) {
}
else {
builder.Services.AddLettuceEncrypt();
builder.WebHost.UseKestrel(k => {
var appServices = k.ApplicationServices;
k.Listen(IPAddress.Any, 80);
k.Listen(IPAddress.Any, 443,
o => o.UseHttps(h => {
h.UseLettuceEncrypt(appServices);
}));
k.ConfigureHttpsDefaults(h => {
h.UseLettuceEncrypt(appServices);
});
});
}
var app = builder.Build();
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();
我找到了serilog.aspnetcore,并安装了该软件包。 github home https://github.com/serilog/serilog-aserilog-aspnetcore 但是我无法弄清楚如何将其连接
。
// Add services to the container.
builder.Services.AddControllers();
builder.WebHost.UseSerilog(); <<<====
到
warning CS0618: 'SerilogWebHostBuilderExtensions.UseSerilog(IWebHostBuilder, ILogger, bool, LoggerProviderCollection)' is obsolete: 'Prefer UseSerilog() on IHostBuilder'
但我没有Ihostbuilder',但我没有一个iHostbuilder and ihostbuilder and One of sone。我也不能找到带有该扩展程序的包裹
I have this boot code and I am trying to work out how to add Serilog to it.
using Microsoft.AspNetCore.Components.WebAssembly.Server ;
using System.Net;
using Serilog;
using Serilog.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Configure the HTTP request pipeline.
if (builder.Environment.IsDevelopment()) {
}
else {
builder.Services.AddLettuceEncrypt();
builder.WebHost.UseKestrel(k => {
var appServices = k.ApplicationServices;
k.Listen(IPAddress.Any, 80);
k.Listen(IPAddress.Any, 443,
o => o.UseHttps(h => {
h.UseLettuceEncrypt(appServices);
}));
k.ConfigureHttpsDefaults(h => {
h.UseLettuceEncrypt(appServices);
});
});
}
var app = builder.Build();
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();
I found Serilog.AspNetCore and have installed that package. The github home https://github.com/serilog/serilog-aspnetcore says to add UseSerilog but I cannot work out how to wire that in.
I added
// Add services to the container.
builder.Services.AddControllers();
builder.WebHost.UseSerilog(); <<<====
But this is deprecated and says
warning CS0618: 'SerilogWebHostBuilderExtensions.UseSerilog(IWebHostBuilder, ILogger, bool, LoggerProviderCollection)' is obsolete: 'Prefer UseSerilog() on IHostBuilder'
But I dont have an IHostBuilder and dont see how to make one. Nor can I find a package with that extension
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iHostBuilder
在builder.host
。来自
配置
serilog
的调用变为That
IHostBuilder
is onbuilder.Host
.From the documentation
The call to configure
Serilog
becomes