Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

SelfHosting Log4net SignalR Server

0.00/5 (No votes)
26 May 2013 1  
A log4Net appender with a selfHosting SignalR server.

Introduction

I wrote an Log4net SignalR Server Appender, this Appender starts an SignalR Host on a defined Uri and starts logging when a client connects. The client defines the logging level. if the logging level is below root Root logging level (e.g., Debug and root Level is Error) i change the root logging level, and switch it back when the client (or clients) disconnect. You can connect as many Clients as you want.

I use SignalR because want to see the logs from wherever I want. And I want to connect with so many clients i want.

Background

Did you know these Situations in which you have an Application that work good for months ?. Due logging performance issues you set the logging level to Error or Fatal. When you are about to forget this Application someone say "WTF!?! your application does not work anymore!!". So looking at the log Files something goes terrible wrong. But the Information you need is at Debug logging level and you do not have the rights to change anything.. (including the log4net configuration Files) and the Admin is on Holiday.

That is why I wrote Log4SignalR.

By the way sorry for my bad English.

Using the code 

All you need is to use the Appender is an .NET 4.5 application that is logging to log4net. (I put a Test Client and Server in the solution.)

Copy assemblies or include my project and change your log4net config like this:

<log4net>
    <appender name="SignalRAppender" type="Log4SignalR.SignalRAppender, Log4SignalR">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" />
        </layout>
        <Url value="http://localhost:8080/"/>        
    </appender>
    <root>
        <level value="Warn" />
        <appender-ref ref="SignalRAppender" />
    </root>
</log4net> 

Do not apply a Level Filter or threshold to the appender I clear it both. The client level is the Filter.

If you use this; or have Problems with it, feel free to leave an comment.

History 

Version 1.0.0.0  25.05.2013

Known limitations: Changing rootLogging Level manually at runtime, will be overwritten when a client connects / disconnects. Because I remember the root logging level at startup.

Only the shipped log4Net logging Levels supported. 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here