Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C# 4.0
Tip/Trick

SelfHosting Log4net SignalR Server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
26 May 2013CPOL2 min read 19.8K   478   5   4
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:

XML
<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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy vote of 5 Pin
Win32nipuh8-Jan-15 5:06
professionalWin32nipuh8-Jan-15 5:06 
AnswerRe: My vote of 5 Pin
Jan_Zimmermann9-Jan-15 3:07
Jan_Zimmermann9-Jan-15 3:07 
GeneralRe: My vote of 5 Pin
Win32nipuh9-Jan-15 4:13
professionalWin32nipuh9-Jan-15 4:13 
Hi Jan,
I am testing the Appender.
It works: client receives the records from the server.

Did you try to create any simple html page which can receive log records and display them?
How to create this kind of page?

Thank you,
Oleg.

modified 9-Jan-15 11:54am.

GeneralRe: My vote of 5 Pin
Jan_Zimmermann11-Jan-15 20:05
Jan_Zimmermann11-Jan-15 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.