Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

A log4net Realtime Color Console for ASP.NET

, 26 Jan 2007
An article on how to create a real-time log4net color console viewer for ASP.NET applications.
Log4netAspColorConsole.zip
Log4netAspColorConsole
log4netColorUdpConsole
bin
log4net.dll
log4netUdpConsole.exe
log4netUdpConsole.vbproj.user
Log4netConsoleSample
bin
log4net.dll
Global.asax
Log4netSampleWebApp.vbproj.webinfo
_vti_cnf
_vti_pvt
access.cnf
deptodoc.btr
doctodep.btr
service.cnf
service.lck
services.cnf
_vti_script
_vti_txt
log4netColorUdpConsole.zip
log4netColorUdpConsole
bin
log4net.dll
log4netUdpConsole.exe
log4netUdpConsole.pdb
log4netUdpConsole.vbproj.user
obj
Debug
buildinfo.inf
ConsoleApplication1.exe
ConsoleApplication1.pdb
log4netUdpConsole.exe
log4netUdpConsole.pdb
temp
TempPE
Interop.SalesMechanixOle.dll
Log4netConsoleSampleWebApp
_vti_cnf
_vti_pvt
access.cnf
deptodoc.btr
doctodep.btr
service.cnf
service.lck
services.cnf
_vti_script
_vti_txt
bin
log4net.dll
Global.asax
Log4netSampleWebApp.vbproj.webinfo
Imports System.Net.Sockets
Imports System.Net
Module UdpLogListener
	Private ReadOnly Log As log4net.ILog = _
	 log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

	Sub Main()

		Dim Port As Integer = 8081	   ' <-- remember to use the same port in your web/source app.
		Dim Sender As IPEndPoint
		Dim Client As UdpClient
		Dim Buffer As Byte()
		Dim LogLine As String

		Try
			Sender = New IPEndPoint(IPAddress.Any, 0)
			Client = New UdpClient(Port)

			While True
				Buffer = Client.Receive(Sender)
				LogLine = System.Text.Encoding.Default.GetString(Buffer)
				' The color	coded text is written to the console when Log.{level method} is called.
				' i.e. Log.Info("my info")
				' Optional: Replace your placeholders with whatever you like. [I]=Info, [D]=Debug, etc.
				'			More detail about placeholders in the UdpAppender config below.
				If LogLine.IndexOf("{INFO}") >= 0 Then
					Log.Info(LogLine.Replace("{INFO}", "[I] "))
				ElseIf LogLine.IndexOf("{DEBUG}") >= 0 Then
					Log.Debug(LogLine.Replace("{DEBUG}", "[D] "))
				ElseIf LogLine.IndexOf("{ERROR}") >= 0 Then
					Log.Error(LogLine.Replace("{ERROR}", "[E] "))
				ElseIf LogLine.IndexOf("{WARN}") >= 0 Then
					Log.Warn(LogLine.Replace("{WARN}", "[W] "))
				Else
					' Some other level.
					Log.Warn(LogLine)
				End If
			End While

		Catch e As Exception
			Console.WriteLine(e)
			Console.WriteLine(vbCrLf & "Press any key to close...")
			Console.ReadLine()
		End Try

	End Sub
End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Philip Liebscher
Technical Lead Interactive Data Corporation
United States United States
No Biography provided
Follow on   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 26 Jan 2007
Article Copyright 2007 by Philip Liebscher
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid