SignalR HubConnection.TraceWriter using Event Log

I needed a better way to Trace what my Windows Service was doing while communicating with my SignalR Hub.  Looking over HubConnection.TraceWriter it turns out that it's pretty easy to roll your own Event Log Writer..

After creating an instance of your HubConnection you set the TraceWriter like so

System.Diagnostics.EventLog eventLog1;
HubConnection hub = new HubConnection(strURLToMyHub);
hub.TraceWriter =
new eventLogTraceWriter(eventLog1);


The final code for the TraceWriter

public class eventLogTraceWriter : System.IO.TextWriter {

       public EventLog _eventLog;

       public eventLogTraceWriter(EventLog eventLog) : base(System.Globalization.CultureInfo.InvariantCulture) {

              _eventLog = eventLog;


       public override void WriteLine(string value) {



       public override Encoding Encoding {

              get { return Encoding.UTF8; }



Pretty simple...

Einzelheiten zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.