Reputation: 344
I have written an extension method on ILogger
and need the complier to emit warning to use that extension method whenever someone use an ILogger instance. For example:
ILogger
public static class LoggerExtensions
{
public static ILogger Here(this ILogger logger,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0) {
return logger
.ForContext("MemberName", memberName)
.ForContext("FilePath", sourceFilePath)
.ForContext("LineNumber", sourceLineNumber);
}
}
ILogger
instance will emit warning// at the beginning of the class
private static Serilog.ILogger Log => Serilog.Log.ForContext<MyClass>();
// in the method
Log.Information("Warning: need to use Here() on ILogger") // the compiler emits warning to use Here()
Log.Here().Information("No warning here."); // this is good. No warning
Any help is much appreciated!
Upvotes: 1
Views: 328
Reputation: 34987
Here are some ideas:
Upvotes: 3