serilog/serilog — pull request #127 by fritsduus (2014-04-27 20:57:42+00:00)
Title: Added SelfLog.SendSelfLogToSink

Hi

I love the concepts in Serilog and Seq and have been integrating the solution into one of my applications. When trying to make it really work I found the diagnostics part (ie. SelfLog) to be lacking something.
I configured SelfLog to write to a text file and then I ran my integration tests for the application. Here is a snippet of the SelfLog file after the integration test run:

2014-04-27T22:21:53 Maximium destructuring depth reached.
2014-04-27T22:21:53 The property accessor System.Web.SessionState.HttpSessionState Session threw exception System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Web.HttpException: Session state is not available in this context.
at System.Web.HttpApplication.get_Session()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at Serilog.Parameters.PropertyValueConverter.d__11.MoveNext() in c:\TeamCity\buildAgent\work\6ef9c409c82c3cae\src\Serilog\Parameters\PropertyValueConverter.cs:line 187
2014-04-27T22:21:53 Maximium destructuring depth reached.
2014-04-27T22:21:53 Maximium destructuring depth reached.
2014-04-27T22:21:53 Maximium destructuring depth reached.

It is very hard to correlate these errors with anything in my code... so what to do ??...
It would be nice if I could get these kind of errors written to the configured Sinks. That would make it a lot easier to pinpoint which log lines in my code is generating these errors.
I realize that since SelfLog only has one WriteLine method it is used for all kinds of errors including "Not able to connect to the sink"-kind of errors. So just writting to the sink(s) from the WriteLine method could cause an infinite loop. This pull-request includes a naive atempt to avoid this infinite loop.

Another solution that requires a bit more work would be to make two "WriteLine" methods in the SelfLog: One for critical connection errors and one for more warning like errors, and then write the "warning like errors" to the sink(s).

What are your thoughts on this ?