.Net Installation

Downloading the .Net Package

Use Nuget or an equivalent package manager to download and install ErrLog.IO.

Install-Package errlog.io
dotnet add package errlog.io
paket add errlog.io

 

Configuring the .Net Package

ErrLog.IO has a number of settings available, however only one is required - the API key.

Parameter Type Description
ErrLog.settings.apikey String Your API Key

 

Instantiating ErrLog.IO to Log Errors & Exceptions

There are a number of ways to activate ErrLog.IO within your application. The first examples are by utilizing the Application_Error method in global.asax for both WebForms and MVC.

protected void Application_Error(object sender, EventArgs e)
{			 
	ErrLog.settings.apikey = "[Your-api-key]";
	Exception ex = Server.GetLastError().GetBaseException();
	ErrLog.logger.log(ex);
}
Protected Sub Application_Error(sender As Object, e As EventArgs)
	ErrLog.settings.apikey = "[Your-api-key]"
	Dim ex As Exception = Server.GetLastError().GetBaseException()
	ErrLog.logger.log(ex)
End Sub

The next example demonstrates how to catch errors in a console or similar application using the CurrentDomain_UnhandledException methods.

static void Main(string[] args)
{
	AppDomain.CurrentDomain.UnhandledException += 
		new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
	ErrLog.settings.apikey = "[Your-api-key]"
	Exception ex = (Exception)args.ExceptionObject;
	ErrLog.logger.log(ex);
}
Private Shared Sub Main(args As String())
	AppDomain.CurrentDomain.UnhandledException += 
		New UnhandledExceptionEventHandler(AddressOf CurrentDomain_UnhandledException)
End Sub

Private Shared Sub CurrentDomain_UnhandledException(sender As Object, args As UnhandledExceptionEventArgs)
	Dim ex As Exception = DirectCast(args.ExceptionObject, Exception)
	ErrLog.logger.log(ex)
End Sub

 

Alternative Methods - Try Catch Blocks

You can also capture errors within a try/catch block, using this simple method:

try {
		...do something that might fail...
	}
catch(Exception ex)
	{
		ErrLog.logger.log(ex);
	}
}
Try 
	...do something that might fail...
Catch ex As Exception
	ErrLog.logger.log(ex)
End Try

 

Alternative Methods - Application_Error

Exceptions can also be caught globally in a .Net application by using the global.asax.cs/vb class.

protected void Application_Error(object sender, EventArgs e)
{			 
	ErrLog.settings.apikey = "[Your-api-key]";
	Exception ex = Server.GetLastError().GetBaseException();
	ErrLog.logger.log(ex);
}
Protected Sub Application_Error(sender As Object, e As EventArgs)
	ErrLog.settings.apikey = "[Your-api-key]"
	Dim ex As Exception = Server.GetLastError().GetBaseException()
	ErrLog.logger.log(ex)
End Sub

 

Optional Parameters

ErrLog.IO has a number of settings available, however only one is required - the API key.

Optional Parameters

 

Discuss this article