Skip to content

[API Proposal]: Add the ResourceType and ResourceName properties to the [LoggerMessageAttribute] #100759

Open
@Abdragiz

Description

@Abdragiz

Background and motivation

Currently, it seems that using resource strings with the logging source generator is not possible. I suggest adding the ResourceName and ResourceType properties to the [LoggerMessageAttribute], similar to the ErrorMessageResourceName and ErrorMessageResourceType properties used in the ValidationAttribute.

API Proposal

public LoggerMessageAttribute (int eventId, Microsoft.Extensions.Logging.LogLevel level, Type resourceType, string resourceName);

API Usage

Given LoggingResource.resx resource strings file and UnexpectedError name, the new API could be used like this:

public static class LoggingExtensions
{
    [LoggerMessage(LogLevel.Error, 0, typeof(LoggingResource), nameof(LoggingResource.UnexpectedError))]
    public partial void UnexpectedError(this ILogger, Exception exception);
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions