chore(Orleans.Runtime): Use [LoggerMessage]#9316
Conversation
src/Orleans.Runtime/Cancellation/CancellationSourcesExtension.cs
Outdated
Show resolved
Hide resolved
src/Orleans.Runtime/Cancellation/CancellationSourcesExtension.cs
Outdated
Show resolved
Hide resolved
src/Orleans.Runtime/Cancellation/CancellationSourcesExtension.cs
Outdated
Show resolved
Hide resolved
|
trying github copilot edits with the following prompt: Replace usages of ILogger methods with a log method annotated with [LoggerMessage] if there's a private field of type ILogger make the generated method If the log method is wrapped in an when a method call is passed to the log message, create a struct that receives the object and overrides the ToString to call the method that was previously passed to the log message. the struct should be a nested The generated methods should be at the end of the class, the generated struct should be right before the generated methods. Examples: Example 1: _shared.Logger.LogWarning( (int)ErrorCode.Dispatcher_ExtendedMessageProcessing, "Current request has been active for {CurrentRequestActiveTime} for grain {Grain}. Currently executing {BlockingRequest}. Trying to enqueue {Message}.", currentRequestActiveTime, ToDetailedString(), _blockingRequest, message);should be converted to a method LogWarningDispatcher_ExtendedMessageProcessing(_shared.Logger, currentRequestActiveTime, new(this), _blockingRequest, message)where the signature of the method would be [LoggerMessage(
EventId = (int)ErrorCode.Dispatcher_ExtendedMessageProcessing,
Level = LogLevel.Warning,
Message = "Current request has been active for {CurrentRequestActiveTime} for grain {Grain}. Currently executing {BlockingRequest}. Trying to enqueue {Message}."
)]
private static partial void LogWarningDispatcher_ExtendedMessageProcessing(ILogger logger, TimeSpan currentRequestActiveTime, ActivationDetailsLogValue grain, Message blockingRequest, Message message)
convert all of the remaining logger methodsExample 2: if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("DeactivateActivations: {Count} activations.", list.Count);
}should be converted to a method LogDebugDeactivateActivations(list.Count)where the signature of the method would be [LoggerMessage(
Level = LogLevel.Debug,
Message = "DeactivateActivations: {Count} activations."
)]
private partial void LogDebugDeactivateActivations(int count) |
|
Could this include some adjustments to messages and log levels to make it more useful to enable information logs on the server? There's a few that considering the content I think are best to be at Trace level. |
@alrz can you comment on the specific log messages? |
|
@ReubenBond ready for review now, there are a few remaining #if DEBUG
if (_gateway.logger.IsEnabled(LogLevel.Trace)) _gateway.logger.LogTrace(
#endifwhich I didn't modify (maybe in a follow up, and the class |
4c6bab5 to
af5f495
Compare
|
@ReubenBond ready for review |
part of #9273
Microsoft Reviewers: Open in CodeFlow