Chat Support
Loupe - Log - Monitor - Resolve
Loupe / Developer's Guide / For .NET Core / 6 / 8 / Agent Configuration / Developer's Guide - Agent Configuration through Code
In This Topic
    Developer's Guide - Agent Configuration through Code
    In This Topic

    Adding the Loupe Agent to your Application

    The first step is to add the core Loupe Agent to your application via NuGet.  To simplify configuration in .NET Core / .NET 5 it's also recommended to add the Loupe Agent Services via NuGet.  You can then build on this with additional technology specific agents as you desire.

    Configuring with Code

    To extend or modify the configuration of Loupe during application startup, provide a configuration builder method to the AddLoupe call. 

    If you don't have this extension method, be sure you have added the Loupe.Agent.Core.Services package via NuGet.
    Simple Agent Configuration Through Code
    Copy Code
            
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .AddLoupe(config =>
                    {
                        config.Publisher.EnvironmentName = "Demo";
                        config.NetworkViewer.AllowRemoteClients = true;
                    });
    }
    

    Of course, your application will typically have more lines in your HostBuilder configuration for other parts of your application.  For example, if you're using Microsoft.Extensions.Logging as your logging API (or to capture information sent to it by other components of .NET Core) you'll want to add the AddLoupeLogging call to add the Loupe listener so that information is appended to the Loupe log too.

    If using the Loupe Agent Builder to extend the Loupe Agent with additional monitoring (for ASP.NET Core, EF Core, and others) you would specify the configuration builder after the agent builder, like this example

    Complete HostBuilder Example
    Copy Code
            
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .AddLoupe(builder => builder.AddAspNetCoreDiagnostics()
                    .AddEntityFrameworkCoreDiagnostics()
                    .AddPerformanceCounters(),
                    config =>
                    {
                        config.Publisher.EnvironmentName = "Demo";
                        config.NetworkViewer.AllowRemoteClients = true;
                    })
                .AddLoupeLogging();
    }
    

     

    See Also