Johannes M
❔ Serilog Extend LogLevels or Intercept Logs
I am using Serilog and I have a specific use case right. I got three sinks (Console, File, SQLServer) and for each I am filtering based on loglevel.
Is there a way in which I can have an interceptor of sorts that when I log a level of Information but with a specific identifier it logs to a different sink and if it doesn't then log to the default sink configured
3 replies
✅ AutoMapper - mapping record to a class (.NET 7)
I am using mediatr for my project and I have my command using a sealed record and when I try to map my record to my entity I run into an AutoMapper Extension error.
Error: Exception thrown: 'AutoMapper.AutoMapperMappingException' in AutoMapper.dll
CODE:
When my CreateProductCommand was still a class the mapping worked with no issues.
12 replies
✅ EF Core migrations at design time using Clean Architecture - .NET 7
I am currently working on a project using clean architecture with Blazor Server. I have my connection string inside the web project but I would like to create my db migrations inside the infrastructure project where my DbContext is sitting. I have a method that will run any outstanding migrations on project startup but when I want to manually create my migrations or update my database using
add-migration
or update-database
. Each time I try this I get an error that it cannot create my DbContext and I should look at the design time on the MS docs. My way around this was creating a configbuilder inside of the infra project and adding a new appsettings.json file and it worked,
Is there a way in which I don't have to create a config builder inside my context factory referencing an appsettings.json file inside of the infra project?
When the project runs I am able to inject the connection string via the DI container and IOptions but this does not work when the project is not running.
34 replies
❔ Using HttpContext outside of a controller/request pipeline (.NET 7)
Hi there I am currently busy with porting a "legacy" system from .NET Framework MVC to .NET Core MVC 7 and struggling with implementing some "global" state. Previously the project used the static accessor from System.Web but whenever I try using
IHttpContextAccessor
outside of a controller or a service I am calling inside of a controller I do not have access. I would like to have a class where I can store some static properties that I use throughout the project. Currently I am trying to use the Session State but when using it outside of the request pipeline the HttpContext will be null. I have some classes that are not used inside of a controller that need access to the HttpContext Session State. I have created a scoped service that I can call inside of controllers or request pipeline and the functionality works but once I step outside of the pipeline I have no access. Any advice is welcome.
Behavior trying to replicate:
28 replies