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

Enabling logging enrichment effects the logged message #4795

Closed
jamiewinder opened this issue Dec 6, 2023 · 1 comment · Fixed by #4798
Closed

Enabling logging enrichment effects the logged message #4795

jamiewinder opened this issue Dec 6, 2023 · 1 comment · Fixed by #4798
Assignees
Labels
area-telemetry bug This issue describes a behavior which is not expected - a bug.

Comments

@jamiewinder
Copy link

Description

Using EnableEnrichment on ILoggingBuilder causes the Message of the log events to be some type name.

Reproduction Steps

Example:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.Enrichment;
using Microsoft.Extensions.Logging;
using System.Text.Json;

var services = new ServiceCollection();

services.AddLogging(x => x
    .EnableEnrichment()
    .AddJsonConsole(y =>
    {
        y.JsonWriterOptions = new JsonWriterOptions()
        {
            Indented = true
        };
    }));

var serviceProvider = services.BuildServiceProvider();

var logger = serviceProvider.GetRequiredService<ILogger<object>>();

logger.LogInformation("this is a test");

This outputs

{
  "EventId": 0,
  "LogLevel": "Information",
  "Category": "object",
  "Message": "this is a test",
  "State": {
    "Message": "Microsoft.Extensions.Logging.ExtendedLogger\u002BLegacyTagJoiner",
    "{OriginalFormat}": "this is a test"
  }
}

If you disable / comment out the EnableEnrichment line:

{
  "EventId": 0,
  "LogLevel": "Information",
  "Category": "object",
  "Message": "this is a test",
  "State": {
    "Message": "this is a test",
    "{OriginalFormat}": "this is a test"
  }
}

Note the State.Message property value.

Expected behavior

The State.Message property should be unaffected.

Actual behavior

The State.Message property is the string "Microsoft.Extensions.Logging.ExtendedLogger\u002BLegacyTagJoiner"

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@jamiewinder jamiewinder added bug This issue describes a behavior which is not expected - a bug. untriaged labels Dec 6, 2023
@geeknoid
Copy link
Member

geeknoid commented Dec 7, 2023

Oh, that shouldn't be. Thanks for the report.

@geeknoid geeknoid self-assigned this Dec 7, 2023
geeknoid pushed a commit that referenced this issue Dec 7, 2023
And while I was in the neighborhood, also address
geeknoid pushed a commit that referenced this issue Dec 8, 2023
And while I was in the neighborhood, also address
@ghost ghost added the work in progress 🚧 label Dec 8, 2023
geeknoid added a commit that referenced this issue Dec 11, 2023
…uments. (#4798)

* Fix #4795

And while I was in the neighborhood, also addresses #4637

---------

Co-authored-by: Martin Taillefer <mataille@microsoft.com>
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
@ghost ghost removed the work in progress 🚧 label Dec 11, 2023
sebastienros added a commit that referenced this issue Dec 18, 2023
* Address issue with legacy logger's calling ToString on the TState arguments. (#4798)

* Fix #4795

And while I was in the neighborhood, also addresses #4637

---------

Co-authored-by: Martin Taillefer <mataille@microsoft.com>
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>

* Add missing [GeneratedCode] attribute (#4802)

The logging code generator emits a static lambda. The lambda's containing
function is annotated with the [GeneratedCode] attribute, but the lambda
itself is not. The result is that code generators can get confused,
considering the lambda as being user code.

This PR adds the [GeneratedCode] attribute to the lambda.

Co-authored-by: Martin Taillefer <mataille@microsoft.com>

* Add more information and sample to Http.Diagnostics Readme (#4808)

* Add more information and sample to Http.Diagnostics Readme

* Simplify first statement and adding using statements.

* Also add extra docs to xml docs

* Improve code coverage for M.E.Diagnostics.Testing (#4820)

---------

Co-authored-by: Martin Taillefer <geeknoid@users.noreply.github.com>
Co-authored-by: Martin Taillefer <mataille@microsoft.com>
Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
Co-authored-by: Jose Perez Rodriguez <joperezr@microsoft.com>
Co-authored-by: Sébastien Ros <sebastienros@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-telemetry bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants