Click here to Skip to main content
15,895,423 members
Articles / Web Development / ASP.NET

A log4net Realtime Color Console for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (17 votes)
26 Jan 2007CPOL4 min read 97.9K   1.3K   69  
An article on how to create a real-time log4net color console viewer for ASP.NET applications.
' This normally should go in AssemblyInfo.vb
<Assembly: log4net.Config.Repository("SampleWebApp")> 
<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="log4net.config", Watch:=True)> 

Public Class _Default
	Inherits System.Web.UI.Page
	Protected WithEvents Refresh As System.Web.UI.WebControls.Button
	Protected WithEvents ThrowError As System.Web.UI.WebControls.Button

	Protected Shared ReadOnly Log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

	Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

		Log.Info("Page_Init...")

	End Sub

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Log.Info("Page_Load...")

	End Sub

	Private Sub Refresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Refresh.Click

		Log.Info("Refresh_Click...")

	End Sub

	Private Sub ThrowError_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThrowError.Click
		Try
			Log.Info("ThrowError_Click...")
			Throw New ApplicationException("An application error has occurred!", New Exception("Inner Exception"))
		Catch ex As Exception
			Log.Error(ex)
		End Try
	End Sub

End Class

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)


Written By
Software Developer (Senior) @Everywhere
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions