Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure serilog in multiple project assembly #339

Open
Aksh-kumar opened this issue Jul 7, 2023 · 4 comments
Open

configure serilog in multiple project assembly #339

Aksh-kumar opened this issue Jul 7, 2023 · 4 comments
Labels

Comments

@Aksh-kumar
Copy link

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

@Aksh-kumar Aksh-kumar added the bug label Jul 7, 2023
@Aksh-kumar
Copy link
Author

Aksh-kumar commented Jul 14, 2023

@julian94 can you please take a look, or assign it to somebody who can help.

@julian94
Copy link
Contributor

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.

  1. 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.
  2. You're on GitHub, why on earth are you sharing source code in a zip file instead of making a new public repository?
  3. The solution file has 11 project files, and zero readme files.
  4. The code is inconsistently formatted, try running dotnet format.
  5. I don't get an error from "https://localhost:7085/api/v1/WeatherForecast/WeatherForecast/get", so I can't reproduce the bug.
  6. Why do you have different routes for GET and POST commands? The norm is for them to have the same routes.

@Aksh-kumar
Copy link
Author

@julian94 Answer of your concerns.

  1. Issue with Serilog is I am not able to set log information display in my console. is it displayed in yours?
  2. World.CleanArchitecture it's not an production project, I was trying to implement clean architecture with repository pattern, this is just an experimental project.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

@julian94
Copy link
Contributor

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants