Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option - [assembly: LogMinimalMethodName] #649

Open
GW-Kang opened this issue Mar 3, 2022 · 3 comments
Open

Add option - [assembly: LogMinimalMethodName] #649

GW-Kang opened this issue Mar 3, 2022 · 3 comments

Comments

@GW-Kang
Copy link

GW-Kang commented Mar 3, 2022

Is the proposal related to a problem

We can clearly know the class that writes the log through the following syntax generated by Anotar.
static ILogger logger = Log.ForContext();

Also know LineNumber through Anotar's elegant feature.
Therefore, since Class and LineNumber are recorded accurately, there is no confusion about which method logs the log due to method overloading.

Given these circumstances, it can sometimes feel superfluous to log the full specification of a Method.
This becomes even worse when there are many parameters of the method.

Describe the solution

So my proposal is that it would be useful to be able to change the behavior like below via [assembly: LogMinimalMethodName] option.

  • today :

In NLog

logger.Debug("Method: 'Void MyMethod(Int32, Int32, String, String, String)'. Line: ~12. TheMessage");

In Serilog

logger
.ForContext("MethodName", "Void MyMethod(Int32, Int32, String, String, String)")
.ForContext("LineNumber", 8)
.Debug("TheMessage");
  • with [assembly: LogMinimalMethodName] option :

In NLog

logger.Debug("Method: 'MyMethod'. Line: ~12. TheMessage");

In Serilog

logger
.ForContext("MethodName", "MyMethod")
.ForContext("LineNumber", 8)
.Debug("TheMessage");
@ltrzesniewski
Copy link
Member

It would be better to configure that in FodyWeavers.xml instead of an attribute.

@GW-Kang
Copy link
Author

GW-Kang commented Mar 4, 2022

Wherever it is configured, I think all would be good.

Just because Anotar already has a configuration method that starts with '[assembly:' as shown below, I thought that a similar implementation would be simpler.

[assembly: LoggerFactoryAttribute(typeof(MyUtilsLibrary.LoggerFactory))]
[assembly: LogMinimalMessage]

@SimonCropp
Copy link
Member

LoggerFactoryAttribute is in an attribute so it can be type safe

@ltrzesniewski is correct it should be in FodyWeavers.xml

@GW-Kang Sounds good. happy to accept a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants