serilog/serilog — pull request #85 by paulcbetts (2014-02-15 00:31:34+00:00)
Title: Add source file / line logging via [CallerFileName] and friends

This PR adds source file / line number logging via the C# [CallerFileName] attribute. However, to do this, we have to do some Controversial Stuff (tm), so I'm pushing up this PR before I do the work :cat:

## The Problem

So, the way you use `[CallerFileName]` is that it must be a Default Parameter. This conflicts Pretty Badly with the `params` keyword, since if the log parameters happen to be `string` and `int`, we now match `sourceFile` and `line`, not the `params` like we wanted. :poop:

## Here's what we do

Instead of using `params`, we T4 Template some explicit overloads via template methods, similar to what we do in ReactiveUI in [VariadicTemplates.cs](https://github.com/reactiveui/ReactiveUI/blob/rxui6-master/ReactiveUI/VariadicTemplates.tt). Something like:

```cs
public static void Warn(this ILogger log, string messageTemplate, T0 item0, [CallerFilePath] sourceFile = "", [CallerLineNumber] int line = 0);

public static void Warn(this ILogger log, string messageTemplate, T0 item0, T1 item1, [CallerFilePath] sourceFile = "", [CallerLineNumber] int line = 0);
```

These are all Extension Methods, because they're super boring, and asking every implementer to implement 3 million methods that just proxy to another one is annoying.

## TODO:

- [ ] Move most of the methods on `ILogger` onto an extension class that just proxies to `Write(LogEntry entry)`
- [ ] Create a T4 Template to render the overloads of Info / Warn / Etc