NLog .Net Logging 2 years ago • updated by j.verdurmen 5 months ago 5

Support for the new interpolated strings introducted in c# 6. See also: https://github.com/NLog/NLog/issues/825

Thanks for voting! We have experimented in short with the interpolated strings, (see https://github.com/NLog/NLog/pull/899).

Too bad we have a problem with method resolution, as

logger.Error($"a {var1}") 

will call

logger.Error(string s)

instead of

logger.Error(FormattableString s) 

This is too bad a (wrong IMO) design decision.

We have now the following options:

1, Create a separate LoggerType (implements ILogger) for interpolated strings.

2, Create separate methods for interpolated strings (e.g. ErrorInterpolated($"a")).

3. Test how the overload resolution works when we remove Error(string) (we still have Error<T>(T t)).

If you have experience with this, or just have an opinoin, let us know!

As a huge proponent of interpolated strings (I loathe arg based Format stuff) I'd say any of those sound reasonable.

#3 sounds the best to me. Maybe I should get off my duff and look into that for ya :P

#2 & #1 ... I dunno, they both have their strengths/weaknesses

I added Error(FormattableString) and removed Error(string) and Error(string, object[])

.Error($"{test}") still decodes itself and follows string to Error<T>


Too bad this isn't technical possible.