Which pattern to use for logging? Dependency Injection or Service Locator?

后端 未结 9 953
别那么骄傲
别那么骄傲 2021-01-31 15:51

Consider this scenario. I have some business logic that now and then will be required to write to a log.

interface ILogger
{
    void Log(string stuff);
}

inte         


        
9条回答
  •  梦毁少年i
    2021-01-31 16:01

    We switched all our Logging/Tracing to PostSharp (AOP framework) attributes. All you need to do to create logging for a method is add the attribute to it.

    Benefits:

    • Easy use of AOP
    • Clear separation of concerns
    • Happens at compile time -> Minimal performance impact

    Check out this.

提交回复
热议问题