pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

A naming conflict with Serilog.Log if name the attribute as Log #135

Closed KKacer closed 4 years ago

KKacer commented 4 years ago

I have this code:

[Aspect(Scope.Global)]
[Injection(typeof(LogCall))]
public class LogCall : Attribute
    {
        [Advice(Kind.Around, Targets = Target.Method)]
        public object HandleMethod(
            [Argument(Source.Name)] string name,
            [Argument(Source.Arguments)] object[] arguments,
            [Argument(Source.Target)] Func<object[], object> method)
        {
            Log.Information("Something");
...

As the Log.Information is part of Serilog, it will conflict if I want to make the attribute named Log not LogCall, though I prefer to name it as Log. Do you know a simple way to be able to name that attribute just [Log]?

Regards.

pamidur commented 4 years ago

Yes, remove Serilog from usings at the top of the file, and use full namespace in place, like:

Serilog.Log.Information("Something");
KKacer commented 4 years ago

Aha! :D right, forgot that could use it this way.

KKacer commented 4 years ago

Changed that but found that it will conflict with all the logs inside all the libraries, if the name was LogAttribute it could prevent that. but currently I decided to use another name instead of Log to prevent the need to change all the Log.Somethings in the codes.

pamidur commented 4 years ago

Why not rename it to LogAttribute or LogCallAttribute?

KKacer commented 4 years ago

Still didn't try LogAttribute which guess will work, at first thought maybe it is not possible via your code or you don't suggest that, cause you didn't use 'Attribute' in the names, guessed may cause some troubles in your library, e.g if you were trimming names, ...

Update: yes, attribute fixed the issue with naming conflicts.

pamidur commented 4 years ago

@KKacer it is just personal preference - not to use ...Attribute suffix. As for AspectInjector - it is designed in a way "if it compiles - it is valid code for AspectInjector"

KKacer commented 4 years ago

Yes got it, said that just to clarify why I worried and avoided using 'Attribute' at first, but as you said it worked. All fine, thanks.