Skip to content

A bad designed Class can cause an Exception when using Stringify #1426

@rafaelsc

Description

@rafaelsc

Description
A bad designed Class can cause an Exception when logging with stringification operator.

Reproduction
Log using stringification operator with a instance of a class that can return null in ToString().

        class ABadBehavior
        {
            public override string ToString() => null;
        }
        Log.Information("{$Data}", new ABadBehavior());

Expected behavior
That the Serilog Core doesn't throw an exception. And Log the result like was another null property

Relevant package, tooling and runtime versions
All runtimes and using the lastest Serilog codebase.

Additional context
I find this issue when implementing the C#8 Nullable Reference Type in Serilog codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions