Use .Net Core CLI to download and install the ErrLog.IO.Core package.
dotnet add package errlog.io.core
Vassilis Panos has created a fantastic .Net Core package for ErrLog - check it out below:
Microsoft have a fantastic
quickstart tutorial explaining how to install a .Net Core package from nuget, over.
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 += UnhandledExceptionHandler;
}
public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs ex) {
ErrLog.settings.apikey = "API_KEY_GOES_HERE";
ErrLog.logger.log((Exception) ex.ExceptionObject);
}
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