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

[LSG] Objects logging using @ operator in logging source generator attribute #78013

Closed
Tracked by #77390
vpetrusevici opened this issue Nov 8, 2022 · 6 comments
Closed
Tracked by #77390
Assignees
Milestone

Comments

@vpetrusevici
Copy link

vpetrusevici commented Nov 8, 2022

Description

Hi! Looks like it's impossible to use @ in message template, but it's important for loggers like Serilog, NLog, etc.

Reproduction Steps

I tried to add this:

[LoggerMessage(0, LogLevel.Debug, "MMC request sent {@request}")]
partial void LogRequestSent(RequestRequest request);

and i received this error:

Template '@request' is not provided as argument to the logging method	

using @request in params doesn't change anything.

Expected behavior

Operator @ should be ignored in params names comparison.

Actual behavior

Error appears.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7 rc2
Visual Studio 2022 preview 6.0

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 8, 2022
@ghost
Copy link

ghost commented Nov 8, 2022

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Hi! Looks like it's impossible to use @ in message template, but it's important for loggers like Serilog, NLog, etc.

Reproduction Steps

I tried to add this:

[LoggerMessage(0, LogLevel.Debug, "MMC request sent {@request}")]
partial void LogRequestSent(RequestRequest request);

and i received this error:

using @request in params doesn't change anything.

Expected behavior

Operator @ should be ignored in params names comparison.

Actual behavior

Error appears.

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7 rc2
Visual Studio 2022 preview 6.0

Other information

No response

Author: vpetrusevici
Assignees: -
Labels:

untriaged, area-Extensions-Logging

Milestone: -

@maryamariyan maryamariyan removed the untriaged New issue has not been triaged by the area owner label Nov 8, 2022
@maryamariyan maryamariyan added this to the Future milestone Nov 8, 2022
@maryamariyan
Copy link
Member

do you have a small sample using serilog with this?

@vpetrusevici
Copy link
Author

@maryamariyan Just created https://github.com/vpetrusevici/SerilogSourceGenExample
You should use @ operator to force object json serialization or $ to use .ToString(), but it's impossible with source generation

@vpetrusevici
Copy link
Author

You can also see examples for serilog on their page https://serilog.net/

@tarekgh tarekgh modified the milestones: Future, 8.0.0 Nov 15, 2022
@maryamariyan maryamariyan changed the title Objects logging using @ operator in source generator attribute [LSG] Objects logging using @ operator in logging source generator attribute Nov 16, 2022
@tarekgh
Copy link
Member

tarekgh commented Jan 9, 2023

Fixed by #79038

@DanielTheCoder
Copy link

Is there a plan to backport this to .NET 6. Would be helpful.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants