TL;DR
Write your own custom analyzer for your class/methods basing it on the Microsoft one.
Details
This diagnostic is specific to the Microsoft provided logging types and is reported for their methods via LoggerMessageDefineAnalyzer based on types and method parameters naming conventions:
context.RegisterCompilationStartAction(context =>
{
var wellKnownTypeProvider = WellKnownTypeProvider.GetOrCreate(context.Compilation);
if (!wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftExtensionsLoggingLoggerExtensions, out var loggerExtensionsType) ||
!wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftExtensionsLoggingILogger, out var loggerType) ||
!wellKnownTypeProvider.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftExtensionsLoggingLoggerMessage, out var loggerMessageType))
{
return;
}
context.RegisterOperationAction(context => AnalyzeInvocation(context, loggerType, loggerExtensionsType, loggerMessageType), OperationKind.Invocation);
});
// ... somewhere in AnalyzeInvocation
if (containingType.Equals(loggerExtensionsType, SymbolEqualityComparer.Default))
{
usingLoggerExtensionsTypes = true;
context.ReportDiagnostic(invocation.CreateDiagnostic(CA1848Rule, methodSymbol.ToDisplayString(GetLanguageSpecificFormat(invocation))));
}
else if (
!containingType.Equals(loggerType, SymbolEqualityComparer.Default) &&
!containingType.Equals(loggerMessageType, SymbolEqualityComparer.Default))
{
return;
}
and:
// ....
if (FindLogParameters(methodSymbol, out var messageArgument, out var paramsArgument))
// ... somewhere in FindLogParameters:
if (parameter.Type.SpecialType == SpecialType.System_String &&
(string.Equals(parameter.Name, "message", StringComparison.Ordinal) ||
string.Equals(parameter.Name, "messageFormat", StringComparison.Ordinal) ||
string.Equals(parameter.Name, "formatString", StringComparison.Ordinal)))
{
message = parameter;
}
You can roll out your own Microsoft.Extensions.Logging.LoggerExtensions class with your methods and it even will work (though 1) it probably is brittle 2)you need to follow the naming conventions):
namespace Microsoft.Extensions.Logging;
public static class LoggerExtensions
{
public static void MyLogInformation(this ILogger logger, string? message, params object?[] args)
=> logger.Log(LogLevel.Information, message, args);
}


But this breaks analysis for the Microsoft provided one:

And probably can cause some other issues.
My recommendation is to roll out your own custom analyzer for your specific methods basing it on the code of the Microsoft one.