Skip to content

Expose SilentLogger as Logger.None #1105

@invino4

Description

@invino4

Does this issue relate to a new feature or an existing bug?

  • Bug
  • [x ] New Feature

What version of Serilog is affected? Please list the related NuGet package.
2.6.0

**What is the target framework and operating system? See [target frameworks]

  • [x ] netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

Please describe the current behavior?
There is no mechanism for creating a Serilog.ILogger that does nothing.

Please describe the expected behavior?
I sometimes use an optional pattern for logging in libraries such as:

        public SomeClass(ILogger logger = null)
        {
            m_logger = (logger ?? new SilentLogger).ForContext<SomeClass>();
        }

This allows consumers of the class that aren't using logging to use the abstraction without logging, while those that are can pass in a logger without having all log statements require a condition method operator. Being able to instantiate a SilentLogger makes this cheap.

Is there a better pattern with Serilog for accomplishing this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions