Singleton or Static Logger?

前端 未结 1 1556
梦如初夏
梦如初夏 2021-01-14 17:08

My current C# application is a single executable (EXE) and a few DLLs (so multiple binaries) and I want to create a LOGGER (some simple custom logger that writes to a single

相关标签:
1条回答
  • 2021-01-14 18:03

    You choose between Singleton and Static logger the same way you always choose between the two: Do you want to be able to override methods (or use a Logging interface)? If you use a singleton, you have the opportunity to override methods to change functionality. You can even abstract the behavior away behind an interface.

    With a static class you are now and forever tied to that class, and any changes affect everyone.

    When dealing with my own systems, i have moved towards singleton instanced objects. It gives a level of flexibility not available with static classes.

    0 讨论(0)
提交回复
热议问题