Skip to content

Logger+Scope conceals scope implementations #670

Description

@sbrickey

While troubleshooting some issues, I ended up wanting to externally track the exit/disposal of scopes. I did so by logging "Exit Scope : {Scope.ToString()}"... unfortunately, all I got was the object.ToString implementation which resulted in Logger+Scope.

I ended up with the following changes (I was using an in-project file-copy of Extensions.Logging):

  • Create (empty) interface ILogScope : IDisposable and convert BeginScope return type. Initially this was just for clarity.
  • Convert scopes from being defined as IDisposable to ILogScope
  • Add Name() to ILogScope
  • Logger+Scope.Name() returns a coalesce from _disposables[]?.Name() results until !String.IsNullOrWhitespace

in theory, I could've just modified Logger+Scope.ToString(), but I'd have needed to use reflection to determine whether the implementation was inherited from object.ToString (which is worthless to override).

In the end, I just want some way to implement some sort of ToString, and have it available on the consumption side of Logger.BeginScope... whether that's an interface, extension methods, or something else entirely, makes little difference to me.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions