Add/remove serilog logging level overrides at run time - asp.net-core

I am using Serilog in .Net 6 WebApi and the required serilog settings, including default logging level and few overrides, are currently being set via appsettings. However, I am looking for a way to dynamically add/remove logging level override for additional namespaces during runtime so that I can capture additional logs on demand for troubleshooting issues, without redeploying the application with setting changes. Is this possible? Any guidance available on how this can be achieved?
Thanks!

You can implement a custom configuration provider in .NET Core which reads the configuration from Database. And you may need to implement Reload option as well. So when you update the database - your configuration will get updated. Here are some references which may help you.
Implement a custom configuration provider in .NET
A Refreshable SQL Server Configuration Provider for .NET Core
Creating a custom ConfigurationProvider for a Entity Framework Core source

Related

Issue with Dspring.cloud.bootstrap.enabled on enable cloud config with master 2.4 version

i upgraded my spring boot application to master pom 2.4 version and using cloud configs with the property enabled spring.cloud.bootstrap.enabled = true, I have db password encrypted in cloud properties so by the time i use the db properties i don't have my encryption framework available, so eventually my application failing with invalid username and password .."i have my own encryption service "
i am looking to see load the cloud config properties after i have my encryption service available, but the spring.cloud.bootstrap.enabled makes it load first on application startup, before i upgrade to master pom, i was not using spring.cloud.bootstrap.enabled so i didn't had any issue, with adding the property the order of loading changed, so i am running into an issue. Any help will be greatly appreciated. Thanks
so by the time i use the db properties i don't have my encryption
framework available
Use #DependsOn annotation in the bean that uses the db properties to depend on the encryption framework.

user secrets file gets ignored in asp.net core 6

I have two projects targeted .net 6 and there are no any explicit declarations for using user secrets (I remember, it was required in previous versions to use AddUserSecrets()). Though, one project gets the right config from secrets.json, but another one - tries to get it from appsettings.json.
So, I'm wondering, what's the issue? How the behavior was changed in .net 6?
In .Net6, WebApplication.CreateBuilder initializes a new instance of the WebApplicationBuilder class with preconfigured defaults. The initialized WebApplicationBuilder (builder) provides default configuration and calls AddUserSecrets when the EnvironmentName is Development.
As long as you initialize your web application using the WebHost.CreateDefaultBuilder method, ASP.NET Core automatically picks up your configuration from the secrets.json file in .Net6. If you initialize your application manually or not .Net6, make sure to call the AddUserSecrets-method.
refer to this

Configuring Azure Redis session cache for ASP.NET MVC 5 web application not possible in web.config

We want to use the Azure Redis service as a session cache for our MVC 5 web application.
For that we use Nuget Microsoft.Web.RedisSeessionStateProvider, which was updated to v3.0.2 recently.
However, putting that specific version in the web.config throws an error saying that the session state provider must inherit from SessionStateStoreProviderBase (namespace System.Web.SessionState).
The RedisSessionStateProvider v3.0.2 from the Nuget inherits from SessionStateStoreProviderAsyncBase (namespace Microsoft.AspNet.SessionState), and hence doesn't work.
The web application is running .NET Framework 4.72! So it must be compatible with v3.x according to the release notes.
The only solution so far is to fall back to version 2.x of the Nuget and use that instead.
What am I missing?

RE: Update service reference changes web config

When I update my service references it modifies the web config bindings adding a default contract to the config.
I have already specified my own generic contract to the web.config but every-time I do an Update Service reference it automatically changes what I had and places the default binding.
Anyone know how to prevent this from happening?
I can think of 2 solutions.
Create separate dll that is referencing the service and reference this dll to the main project.
Your main config wont be modified that way.
Use config transformation while compiling app.
This transformation would adapt the default configuration to your own needs.

Using Castle Windsor and the NHibernate facility on shared hosting

I'm attempting to use Windsor and NHibernate in a medium trust environment and I'm running up against some problems with permissions. I have read through the other questions on this but I'm using Windsor's NHibernate facility which I haven't seen discussed.
For some reason there is a dependency on the Castle.Service.Transations assembly when the container starts up. This then tries to create and instance of:
Castle.Services.Transaction.CallContextActivityManager()
A security exception is raised as CallContextActivityManager tires to use SetData in System.Runtime.Remoting.Messaging.CallContext which is only allowed if you have infrastructure permission. I'm guessing that medium trust apps don't.
Does anyone know a way around this security issue in medium trust? Should I dump the NHibernate facility and register it manually with the container?
You can get around this by registering the TLSActivityManager in the container (for type IActivityManager). The DefaultTransactionManager (used by NHibernateIntegrationFacility) will then use this ActivityManager instead of firing off a new CallContextActivityManager.