我有一个控制台应用程序,我试图配置依赖注入,日志记录等。
我已经安装并引用了最新的nuget包。
我意识到我不能将构建器配置为UseSerilog(),因为Serilog.Extensions.Hosting也不能安装。
Error CS0234 The type or namespace name 'Hosting' does not exist in the namespace 'Serilog.Extensions' (are you missing an assembly reference?)
csproj文件在这里:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
</ItemGroup>
不工作的部分(由于未安装Serilog.Extension.Hosting):
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Build())
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
var host = new HostBuilder()
.ConfigureServices((context, services) =>
{
// fill in later
})
.UseSerilog() <---- IHostBulder does not contain a definition for UseSerilog()
.Build();
让我知道我可以回答的其他问题,谢谢!
1条答案
按热度按时间bttbmeg01#
安装
Serilog.Extensions.Hosting
软件包。从github页面:Microsoft.Extensions.Hosting
的串行日志记录。