Comments (3)
Thank you for taking the time to answer. Although, I wasn't satisfied because I see this issue as a breach of the Liskov Substitution Principle.
Hence, I jumped in the code to find where the issue was originating from.
BeginScope(ILogger, String, Object[])
is an extension from the runtime, and therefore, outside of the scope of this repos.
The main concern that prompted me to open this issue, is the fact that the value {OriginalMessage}
is overwritten by whatever is contained in the scope.
I could track down the issue to : source code
The scope values are only added after the state value passed in the Log<TState>()
method.
In this case, since the scope used a FormattedLogValues
, it also includes a key {OriginalFormat}
, which overwrites the one previously created.
To solve the main issue, editing the condition at line 202 of the file as such :
if (item.Key == "{OriginalFormat}")
{
if (!dict.ContainsKey("OriginalFormat"))
dict["OriginalFormat"] = Convert.ToString(item.Value, CultureInfo.InvariantCulture);
}
To solve the secondary issue, but this could have unforseen consequences, knowing that there is an OriginalFormat
key, it could be assumed that the activeScope
uses some kind of formater and just add it to the builder
.
if (item.Key == "{OriginalFormat}")
{
if (!dict.ContainsKey("OriginalFormat"))
dict["OriginalFormat"] = Convert.ToString(item.Value, CultureInfo.InvariantCulture);
builder.Append(" => ").Append(activeScope);
}
from applicationinsights-dotnet.
using (var scope2 = Logger.BeginScope("Executing {Process} : {Id}", processName, id ))
^ do not use this for Scopes. Instead pass in KVP yourself like below:
KeyValuePair<string, object>[] scopeValues = [
new ("Id", id ),
new( "Process", processName),
];
using (var scope = Logger.BeginScope(scopeValues))
{
There are no fixes planned for scopes in this repo - please follow the above suggestion. (Even when you move to openTelemetry, still the above recommendation should be followed.)
from applicationinsights-dotnet.
which overwrites the one previously created.
That is true. There kvpairs in the TraceTelemetry cannot accept duplicates. So if there are more than one OriginalFormat key, only one can remain. This would be the case when you has nested scopes as well.
This issue (#2241) shows other possible cases where the information is lost, along with some ideas to fix. But like I said, there won't be any such fixes in this repos, due to the long term strategy of only using OpenTelemetry exclusively.
And I don't see OTel solving it either, it'll remain user responsibility to not use loggermessage templates in scope, but use only list/ienumeralbe/dic in scopes, or potentially move away from scopes to some other enrichment mechanism.
from applicationinsights-dotnet.
Related Issues (20)
- GRPC Memory Leak HOT 1
- RequestTelemetry missing in HttpContext.Features HOT 2
- App Insights map tile not working on custom dashboards HOT 1
- global property formatted as a datetime
- package may fail to build on certain locales
- Microsoft.ApplicationInsights.WorkerService does not log traces even after specifying override in config HOT 3
- Dependencies to unsupported and end of life nuget packages and frameworks HOT 2
- EventCounterCollectionModule sends events every second HOT 15
- Service registration fails HOT 4
- disable tracking
- Add "area" and "handler" names to Request/Operation name for Razor Pages
- Disable sampling for a specific request HOT 2
- 500.53 URL rewrite module error with message Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ('br')
- Difference in behaviour between Microsoft.Azure.ServiceBus and Azure.Messaging.ServiceBus for adding Activity Tags to telemetry
- Microsoft.Extensions.Logging.ApplicationInsights adds trace IDs a 2nd time to trace telemetry HOT 5
- Live metrics doesn't show logger traces when a custom log level is set HOT 1
- Application Insights does not log dependencies with a profiler attached HOT 1
- When saving custom events to Application Insights, Local Date Time information gets lost (it gets converted to UTC) HOT 2
- Update deprecated package System.Diagnostics.DiagnosticSource
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from applicationinsights-dotnet.