Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.11k stars 79 forks source link

Fix code generation by ZLoggerMessage #134

Closed tetsuzin closed 6 months ago

tetsuzin commented 6 months ago

Fix error when EventName is passed to constructor of ZLoggerMessageAttribute.

before

public partial void EventName(global::Microsoft.Extensions.Logging.ILogger logger, int x, int y)
{
    if (!logger.IsEnabled(LogLevel.Warning)) return;
    logger.Log(
        LogLevel.Warning,
        new EventId(12, EventName), // <-- "EventName" is not string
        new EventNameState(x, y),
        null,
        (state, ex) => state.ToString()
    );
}

after

public partial void EventName(global::Microsoft.Extensions.Logging.ILogger logger, int x, int y)
{
    if (!logger.IsEnabled(LogLevel.Warning)) return;
    logger.Log(
        LogLevel.Warning,
        new EventId(12, "EventName"),
        new EventNameState(x, y),
        null,
        (state, ex) => state.ToString()
    );
}
neuecc commented 6 months ago

thanks!!!