Loupe - Log - Monitor - Resolve
Loupe / Getting Started / Using Loupe with ASP.NET Core
In This Topic
    Using Loupe with ASP.NET Core
    In This Topic

    To cater to the unique needs of ASP.NET Core, Loupe has a dedicated stack of agents designed for .NET Standard 2.0 and later / .NET Core 2.1.  Like .NET Core, Loupe is modular with different assemblies for extending common parts of the .NET Core ecosystem.

    While ASP.NET Core and EF Core support applications developed for the .NET Framework the Loupe agents are designed to work on top of the Loupe Agent for .NET Core exclusively at this time.  If you need them to work for .NET Framework, contact our support team for how to build them for this situation.
     Adding the Loupe Agent to your Application

    Add the the following NuGet packages to get Loupe and its relevant dependencies:

    1. Loupe.Agent.AspNetCore: The main Loupe extension for ASP.NET Core, which will also pull in the main Loupe agent itself.
    2. Loupe.Extensions.Logging: Connects Loupe with the Microsoft.Extensions.Logging infrastructure which is used by ASP.NET for common logging.
    3. Loupe.Agent.Core.Services: A small package with configuration builders for ASP.NET Core.
    4. Loupe.Agent.EntityFrameworkCore (Optional): Connects Loupe with EF Core to record performance and diagnostic information for EF Core.

    To activate the ASP.NET Core Agent you need to add a few lines of code to Startup.cs to add Loupe diagnostics and tracing to your site:

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {    //Add Loupe and connect it to ASP.NET Core & EF Core.
          .AddAspNetCoreDiagnostics() //From Loupe.Agent.AspNetCore
          .AddEntityFrameworkCoreDiagnostics(); //From Loupe.Agent.EntityFrameworkCore
          .AddPerformanceCounters(); //From Loupe.Agent.PerformanceCounters
       //add Loupe as a logger as well
       services.AddLogging(builder =>
             builder.AddLoupe(); //from Loupe.Extensions.Logging
        //Now add all of the relevant other ASP.NET Core services.

    .NET Core uses a different, more flexible, approach to application configuration than .NET Framework applications.  Instead of XML config files .NET Core has an entire extensible configuration subsystem that can be used.  In most situations you'll do a combination of coded configuration and JSON configuration.  For details, see Developer's Guide - Agent Configuration.

    Once you've instrumented an application you'll want to set up a connection with Loupe Server so you can collect data from everywhere your application runs and start managing errors.  Add this configuration to your appsettings.json file to send data to this server automatically in the background.  You'll need to make a few changes to this JSON to have it work:

    • Replace "Your Loupe Service Name" with the name of your Loupe Cloud-hosted Service.  If you don't have one yet, sign up for a free trial service.
    • Replace "Your Product" and "Your Application" with friendly values for your application.  A good analogy for Product is "Office" and Application is "Word", "Excel", and "PowerPoint". 
      "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
          "Default": "Warning"
      "Loupe": {
        "Publisher": {
          "ProductName": "Your Product",
          "ApplicationName": "Your Application",
          "ApplicationType": "AspNet",
          "ApplicationVersionNumber": "1.0.1"
        "Server": {
          "UseGibraltarService": true,
          "Customer": "Your Loupe Service Name",
          "AutoSendSessions": true,
          "SendAllApplications": true

     Packaging and Sending Loupe Data from your Application
    The Loupe Agent provides a comprehensive set of capabilities to gather the session data recorded while your application runs and send it to where you can work with it to fix customer issues, understand feature usage, and drive your product development forward.  This capability is automatically configured as part of the Configuration Wizard, but you can provide an enhanced user experience by reviewing Developer's Guide - Packaging and Sending Data.

    Go Deeper with Loupe

    To get the most out of Loupe, refer to our Developer's Guilde for .NET Core to see how you can create custom metrics, capture extended user information and more!

    See Also