serilog-aspnetcore
serilog-aspnetcore copied to clipboard
configure serilog in multiple project assembly
Can anybody please provide me way to use serilog in my ASP dot net core 6.0 application, I have multiple project assembly and I want to use serilog in all of them, I tried some of the existing solution but I don't se any log printed in console.and more over can you provide me how to use mock logger in Xunit project.I try but it is throwing System.ArgumentException.
Description
Console or file Sink Log output is not getting displayed. In unit test _logger.Object is throwing System.ArgumentException in CreateCountryCommandHandlerTest in line number 33.
Reproduction Just run the code and hit weather-forcast api.
Expected behavior Console and File output should be displayed.
Relevant package, tooling and runtime versions Serilog.AspNetCore (7.0.0)
Additional context Code Zip file is available World.CleanArchitecture.zip
@julian94 can you please take a look, or assign it to somebody who can help.
I am not affiliated with the project, but I took a look at your codebase as requested.
I was unable to find the issue you had with Serilog, but I found some others.
- It's called "World.CleanArchitecture", but the architecture is rather messy. It feels like you tried to cram in unnecessary abstraction and fancy design patterns without much concern about whether it makes sense to do them all in the same project.
- You're on GitHub, why on earth are you sharing source code in a zip file instead of making a new public repository?
- The solution file has 11 project files, and zero readme files.
- The code is inconsistently formatted, try running dotnet format.
- I don't get an error from "https://localhost:7085/api/v1/WeatherForecast/WeatherForecast/get", so I can't reproduce the bug.
- Why do you have different routes for GET and POST commands? The norm is for them to have the same routes.
@julian94 Answer of your concerns.
- Issue with Serilog is I am not able to set log information display in my console. is it displayed in yours?
- World.CleanArchitecture it's not an production project, I was trying to implement clean architecture with repository pattern, this is just an experimental project.
- Yes I should Have it belong to some other repo which is private if I can move it to public which need me to create another public repos and then place it here and I don't want to do that.
- Read me file is not there as I told you it's just an experiment project which have couple of controllers, which I feel like not more explanation is required.
- You can hit any swagger API and put _logger.information() with some string in debugger mode when it hit you will not see any logger in console or output window, that is the problem which solution I am looking.
- I don't understand this one but as far I can see I nly have get in WeatherForecast Controller.
Feel free to post if If you have any other doubt.
Try changing your logging config to not use the options variable, the options stops the configuration from being read properly.
In World.WebApi/Program.cs
builder.Host.UseSerilog((context, configuration) =>
{
configuration
.ReadFrom
.Configuration(context.Configuration);
});