Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Add ILogger methods to write templated messages #55

Closed
lodejard opened this issue Oct 31, 2014 · 2 comments
Closed

Add ILogger methods to write templated messages #55

lodejard opened this issue Oct 31, 2014 · 2 comments

Comments

@lodejard
Copy link
Contributor

  _logger.WriteTemplate(
    TraceType.Information, 
    "writing {filename} took {milliseconds}ms", 
    theFileName, theTimeElapsed); 

Assuming this would take level, messageTemplate, and params object[] values... Assuming there would be other overloads like InformationTemplate and ErrorTemplate that would call the base one with the enum value. I guess there would be overloads that take an exception also...

The extension method would call the ILogger _logger.Write() with the arguments for object state, Exception eception, Func<object, Exception, string> formatter

The state in this case would implement ILoggerStructure, and ILoggerStructure.GetValues() would enumerate the key-value pairs based on {markers} in the template and values in object[].

The formatter in this case would be a callback that downcasts the state object. Assuming the state object is holding onto the information needed to stringify.

@tugberkugurlu
Copy link
Contributor

I cannot resist the temptation as logging is one of my favorite ❤️ topics. So, I will ask 😄

String Interpolation is currently a planned feature for C# 6.0. I wonder how this would look like with string interpolation. I assume it won't effect this as far I can see as the interpolated string seems to be translated to String.Format but I wanted to ask anyway.

@davidfowl
Copy link
Member

This is done.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants