Global Exception Handling in VB.Net Tutorial

A global exception handler is used to catch all unhandled exceptions within a given application. To handle exceptions globally you can use a built in .NET solution, extend a solution or use pre-built solutions. Today we’ll focus on a pre-built solution by ClearInsights.


ClearInsights logging provides integrated exception handling for the .NET framework. You can log exceptions within a try-catch block or implement their easy to integrate global exception handling. A huge benefit to using ClearInsights logging is that new exceptions are automatically added to your team’s backlog when integrated (Ex. Jira project backlog).

ClearInsights Global Exception Handling: Example

Below is an example code showing how to use ClearInsights logging withing your VB.NET applications to handle global exceptions.

Imports ClearInsights.Logging
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Logging

Module Program
    Sub Main(args As String())

        Dim serviceCollection As New ServiceCollection()

        Dim serviceProvider = serviceCollection.BuildServiceProvider()

        'This will automatically catch any unhandled exceptions
        System.AppDomain.CurrentDomain.UseClearInsightsExceptionHandling(serviceProvider.GetService(Of ILogger(Of AppDomain)))

    End Sub

    Private Sub ConfigureServices(ByVal services As IServiceCollection)
                                Return configure.AddClearInsightsLogger(Sub(configuration)
                                                               configuration.ApiKey = "{ApiKey}"
                                                               configuration.Secret = "{Environment Client Secret}"
                                                               configuration.ApplicationName = "{Your Application Name}"
                                                           End Sub)
                            End Function).AddTransient(Of SomeClass)()

    End Sub
End Module

That’s it! Adding these few lines of code to your VB.NET application will enable you to catch all unhandled exceptions and automatically add them to your team’s backlog.

ClearInsights Centralized Application
Logging & Monitoring

Fully integrated application logging and monitoring – enabling software teams and businesses to build fast while having clear insight into their products and applications.

Add ClearInsights Logging with just a few lines of code and automically push new found errors directly to your teams backlog.

 builder.Logging.AddClearInsightsLogger(configuration =>
     configuration.ApiKey = "{ApiKey}";
     configuration.Secret = "{Environment Client Secret}";
     configuration.ApplicationName = "{Application Name}";
ClearInsights community plan is always free for small projects

Leave a Reply