question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override Map not applying correctly

See original GitHub issue

Hi have 2 appsettings in my ASP.NET Core project. Default is Production and override is Development. I have the following code in my configs. In appsettings.json,

"Serilog": {
	"Using": [ "Serilog.Sinks.Async", "Serilog.Sinks.RollingFile" ],
	"MinimumLevel": {
	  "Default": "Information",
	  "Override": {
		"Microsoft": "Warning",
		"System": "Error"
	  }
	},
	"WriteTo": [
	  {
		"Name": "RollingFile",
		"Args": {
		  "pathFormat": "C:/Logfiles/project/log-{Date}.json",
		  "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
		  "fileSizeLimitBytes": 2147483648,
		  "retainedFileCountLimit": 5
		}
	  }
	],
	"Properties": {
	  "Application": "ServiceMyCar.Web.Api"
	}
}

And the overriding appsettings.development.json,

"Serilog": {
	"MinimumLevel": {
	  "Default": "Debug",
	  "Override": {
		"Microsoft": "Information",
		"System": "Information"
	  }
	}
}

So from my understanding, in Development environment, the MinimumLevel should be Debug. In Production environment, the MinimumLevel should be Information. However, for some reason the overriding configuration is not applying. I have attached the output. Serilog

As you can see in the image, HasOverrideMap is true (marked by blue). The LevelSwitch (marked by green) is showing MinimumLevel of the appsettings.json value. And the configuration from appsettings.development.json is loaded under the OverrideMap values. So the configuration has been loaded into the Logger. But in the IsEnabled check, the level for Debug is false. Which means the OverrideMap is not applying. And that’s why I am not seeing the Debug messages from my application.

Can someone help me figure out why this is happening and how I can resolve this problem? I am using latest Serilog versions and using ASP.NET Core 2.2.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tsimbalarcommented, Apr 17, 2019

Just to be sure there is no misunderstanding, let me explain what you are doing, and then you can confirm that it is indeed what you are trying to achieve 😃

When you do Log.ForContext<HttpContext>, this is pretty much equivalent to Log.ForContext("SourceContext", "Microsoft.AspNetCore.Http.HttpContext"), i.e. you are adding a property named SourceContext whose value is the full namespaced-name of the type you pass to the type parameter T in .ForContext<T>. At first glance, this seems a bit strange, as you would normally use .ForContext<T> where T is a type you own. This is typically used to be able to track down which class wrote which log events.

It is the property SourceContext that is taken into account also for “Level Overrides”. As far as I understand, you are therefore writing some of your logs with SourceContext = "Microsoft.AspNetCore.Http.HttpContext", but you have defined some Level Overrides that state that for SourceContext starting with Microsoft.*, only write logs when the event level is > Information

Would this explain what you are seeing ?

If what you are trying to do is attach some properties of the HttpContext to the events you are logging, the expected approach would be to use the form you described later in you description : Serilog.Log.ForContext("RequestHost", context?.Request?.Host) .

If you really want to attach all the properties of HttpContext, then you should be using :

Serilog.Log.ForContext("HttpContext", context, destructureObjects: true)

but this is really not recommended 😛

0reactions
olicoopercommented, May 10, 2020

@skomis-mm yeah it didn’t seem to be supported, that’s a shame. I will do this then thank you 👍 @tsimbalar yeah that’s my fault for not posting an accurate example. This is not my exact setup but I was trying to give an example of adding an entry. Whoops 🤦‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Map get not working even after overriding hashcode ...
When I try to call map.get() using an existing Key (Key with matching cacheId and string key value), I don't get the desired...
Read more >
Override Mapping of My Documents with Group Policy
I'm working with a network of 2008 R2 domain controller and Windows XP & 7 clients. There is already a policy in place...
Read more >
Vray 5 - Material override not correctly mapped on ...
Hello, I am using material override with Vray 5 and just discovered that the material override does not seem work correctly on materials ......
Read more >
UE4 4.20.3 - GameMode Override Not Working
Currrently I am using UE4 4.20.3 and when transitioning from the Main Menu Level to the First Level, the Main Menu GameMode Override...
Read more >
Override Some Default Map Settings? - Wesnoth Forums
To check if they're applied correctly, use :inspect debug command or droid the ai and use the formula ai console.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found