-
Notifications
You must be signed in to change notification settings - Fork 835
Description
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.