Use Nuget or an equivalent package manager to download and install
ErrLog.IO.
Package Manager
Install-Package errlog.io
.NET CLI
dotnet add package errlog.io
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 |
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
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
Exceptions can also be caught globally in a .Net application by using the
global.asax.cs class or global.asax.vb.
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
ErrLog.IO has a number of settings available, however only one is required - the API key.
Optional Parameters