Is it possible to use resource files (.resx) with Compile-time logging source generation?

34 views Asked by At

I have an application that is using simple _logger.LogInformation() api with resource files (.resx).

_logger.LogInformation(LogResource.LogText);

Is it possible to rewrite this code to use the [LoggerMessageAttribute] with resource files?

As I know attribute constructors expect constant expressions, but .resx helpers are static, so this code doesn't work:

internal static partial class LoggerExtensions
{
    [LoggerMessage(Level = LogLevel.Information, Message = LogResource.LogText)]
    public static partial void LogText(this ILogger logger);
}
0

There are 0 answers