Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Add ICombinedSettingsBuilder.Dump() and ICombinedSettingsBuilder.DumpToSelfLog() #11

Merged
merged 3 commits into from
Mar 12, 2018

Conversation

tsimbalar
Copy link
Contributor

To inspect the currently defined key-value settings and help when debugging settings related issues.

Those extension methods are in the Serilog.Debugging namespace.

Note: this PR sits on top of #10 , so I will rebase it properly once #10 has been merged .

@nblumhardt
Copy link
Contributor

Looks great!

Only a thought - perhaps Inspect() would be a passable alternative name to Dump()? I'm struggling to think of how to reword DumpToSelfLog() as InspectSomethingSomethingSelfLog(), though....

@tsimbalar
Copy link
Contributor Author

Yep, Inspect() sounds like a better name than Dump()for the overload accepting a Action<IEnumerable<KeyValuePair<string, string>>>.

Maybe PrintToSelfLog() is a better name ? I do like DumpToSelfLog, though, as I think it's a bit clearer that it is a one-off , debugging thing ...

The Dump()name is inspired by LINQPad :)

To inspect the currently defined key-value settings and help when debugging settings related issues
@tsimbalar tsimbalar changed the title [WIP] Add ICombinedSettingsBuilder.Dump() and ICombinedSettingsBuilder.DumpToSelfLog() Add ICombinedSettingsBuilder.Dump() and ICombinedSettingsBuilder.DumpToSelfLog() Mar 8, 2018
@nblumhardt
Copy link
Contributor

Not sure if it's a useful suggestion .. but we could always just include Inspect(), and then let the user foreach over the keys and send them to the console/wherever they are conveniently read from. It's nice having the simple to-selflog option, but since it does require finding and setting up the SelfLog, the overall lines-of-code count is similar whether we include the method or not :-)

@tsimbalar
Copy link
Contributor Author

agreed :)

@tsimbalar
Copy link
Contributor Author

I've done the change. There is now only .Inspect(Action<IEnumerable<KeyValuePair<string, string>>>).

}
else
{
SelfLog.WriteLine($"{nameof(Inspect)} called on a {nameof(ICombinedSettingsBuilder)} that is not a {nameof(CombinedSettingsBuilder)}. Cannot dump the key-value pairs. Concrete type is {self.GetType()}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thought, do we need the interface here, or would just using the concrete type throughout eliminate this type of issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean getting rid of the ICombinedSettingsBuilder interface all together ? That would mean making the concrete calss CombinedSettingsBuilder public and sealedtoo, I guess ... I don't have strong opinions on that, just that using interfaces seemed more pure when doing fluent-interface-y stuff :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and make the constructor internal also.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the gist of what I had in mind, but could be pros/cons. Classes and/or ABCs do generally evolve a bit better (it's not a breaking change to add a method, for example), but could be other reasons to prefer an interface here - just an idea :-)

@tsimbalar
Copy link
Contributor Author

Following your suggestions, I got rid of ICombinedSettingsBuilder in favor of using a concrete class CombinedSettingsBuilder. This should make it easier to extend it without breaking client code down the line.

It's probably paranoia talking, but I have :

  • made the class sealed because we don't expect subclassing to be used for extension (at least not for now)
  • made the constructor internal because we expect people to interact with an already provided instance, not to build their own
  • made the method IEnumerable<KeyValuePair<string, string>> BuildSettings() internal for now ... although I feel a bit strange about having a class called XXXBuilder without a BuildXXX() method 😛

I believe it will still be OK to unlock it later on if we need to :)

@nblumhardt
Copy link
Contributor

Paranoia is welcome here :-)

@nblumhardt nblumhardt merged commit 28edaf1 into serilog-archive:dev Mar 12, 2018
@tsimbalar tsimbalar deleted the debugging-dump branch March 12, 2018 19:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants