Reputation: 1941
I'm trying to call loggerFactory.AddSerilog(); as per this documentation, but the AddSerilog method is not recognized:
"Error CS1061 'ILoggerFactory' does not contain a definition for 'AddSerilog' and no extension method 'AddSerilog' accepting a first...".
I'm using ASP.NET CORE with the full .NET framework. What am I doing wrong?
Upvotes: 52
Views: 43595
Reputation: 169
If you have package Serilog.Extensions.Logging
added to your project already, it could be just a matter of adding using Serilog;
to the top of your code file.
Upvotes: 3
Reputation: 402
On .NET Core 3.1, within a console app, I simply had to install the serilog.extentions.hosting NuGet package.
This will add the below line to the ItemGroup within YourProjectName.csproj
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.7" />
Upvotes: 5
Reputation: 924
Different circumstance, but same problem. In my case, I was using .Net Core 2.1 and had a NuGet reference to Serilog, but was missing a reference to Serilog.AspNetCore. The issue first manifested as .UserSerilog() not being found for the IWebHostBuilder of my CreateWebHostBuilder static method under Program.cs.
Adding the Serilog.AspNetCore NuGet package to my project solved the problem.
Upvotes: 42
Reputation: 996
You may forget this following line in project.json
"Serilog.Extensions.Logging": "1.0.0",
See also https://carlos.mendible.com/2016/09/19/step-step-serilog-asp-net-core/
Upvotes: 98
Reputation: 17538
The posted answer is correct but I will add that you may want to use the NuGet package manager that way you can get the latest version.
Right click on solution
-> Choose "Manage NuGet packages for solution"
-> type "serilog.extensions.logging" into search box
-> Click on Serilog.Extensions.Logging and press install
You will get a dropdownlist of the different versions you should choose the latest.
Or quicker from Package Manager console verify that Default Project drop-down has your project selected and run
install-package Serilog.Extensions.Logging
Upvotes: 24