Moesif.Middleware 1.3.3

.NET Middleware to log API Calls to Moesif API Analytics and Monitoring

Install-Package Moesif.Middleware -Version 1.3.3
dotnet add package Moesif.Middleware --version 1.3.3
<PackageReference Include="Moesif.Middleware" Version="1.3.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Moesif.Middleware --version 1.3.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Moesif Middleware for .NET

Middleware SDK that captures incoming or outgoing API calls from .NET apps and sends to Moesif API Analytics.

Source Code on GitHub

How to install

Install the Nuget Package:

Install-Package Moesif.Middleware

This SDK supports both .NET Core 2.1 or higher and .NET Framework 4.5 or higher. Jump to installation for your specific framework:

Net Core installation

In Startup.cs file in your project directory, please add app.UseMiddleware&lt;MoesifMiddleware&gt;(moesifOptions); to the pipeline.

To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.

Add the middleware to your application:

using Moesif.Middleware;

public class Startup {

    // moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
    Dictionary<string, object> moesifOptions = new Dictionary<string, object>
    {
        {"ApplicationId", "Your Moesif Application Id"},
        {"LogBody", true},
        ...
        # For other options see below.
    };

    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        app.UseMiddleware<MoesifMiddleware>(moesifOptions);
        app.UseMvc();
    }
}

Your Moesif Application Id can be found in the Moesif Portal.
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging
into the Moesif Portal, click on the top-right menu,
and then clicking Installation.

.NET Core example

Checkout the examples
using .NET Core 2.0 and .NET Core 3.0

NET Framework installation

In Startup.cs file in your project directory, please add app.Use&lt;MoesifMiddleware&gt;(moesifOptions); to the pipeline.

To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.

Add the middleware to your application:

using Moesif.Middleware;

public class Startup {
    
    // moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
    Dictionary<string, object> moesifOptions = new Dictionary<string, object>
    {
        {"ApplicationId", "Your Moesif Application Id"},
        {"LogBody", true},
        ...
        # For other options see below.
    };

    public void Configuration(IAppBuilder app)
    {
        app.Use<MoesifMiddleware>(moesifOptions);
    }
}

Your Moesif Application Id can be found in the Moesif Portal.
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging
into the Moesif Portal, click on the top-right menu,
and then clicking Installation.

Add OWIN dependencies

IIS integrated pipeline

If you're running your .NET app on IIS (or Visual Studio IIS Express) using integrated mode (most common), you will have to install the OWIN SystemWeb package if not done so already:
Review OWIN Middleware in the IIS integrated pipeline for more info.

Install-Package Microsoft.Owin.Host.SystemWeb

Moesif does not support IIS running in Classic mode (Backwards compatibility for IIS 6.0). Unless your app predates IIS 6.0 and requires classic mode, you should switch to integrated mode.
{: .notice--primary}

Self-Host executable

While uncommon, if your application is a self-hosted executable that does not run on IIS, you may have to install the SelfHost package if not done so already:

For .NET Web API applications:

Install-Package Microsoft.AspNet.WebApi.OwinSelfHost

For all other .NET applications:

Install-Package Microsoft.Owin.SelfHost -Pre

.NET Framework Examples

The following examples are available for .NET Framework with Moesif:

Troubleshooting

Legacy website broken/Can I activate on API only?

If your .NET app is a traditional monolith consisting of both an API and website, you can choose to activate the middleware
on just your API only. Some legacy apps may have delicate and custom middleware chains.
An easy way to do that is via MapWhen:

    app.MapWhen(context => context.Request.Path.ToString().Contains("/api"), appBuilder =>
    {

        appBuilder.Use<MoesifMiddleware>(new System.Collections.Generic.Dictionary<string, object> {
            {"ApplicationId", "Your Moesif Application Id"}
        });
    });

How to test

  1. Manually clone the git repo
  2. From terminal/cmd navigate to the root directory of the middleware.
  3. Invoke 'Install-Package Moesif.Middleware'
  4. Add your own application id to 'Moesif.Middleware.Test/MoesifMiddlewareTest.cs'. You can find your Application Id from Moesif Dashboard -> Top Right Menu -> Installation
  5. The tests are contained in the Moesif.Middleware.Test project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.

Tested versions

Moesif has validated Moesif.Middleware against the following framework.

| | Framework Version |
| -------------- | ----------------- |
| .NET Core|2.0-3.0|
| .NET Framework MVC |4.5-4.7|
| .NET Framework Web API|4.5-4.7|
| .NET Framework Web API SelfHost|4.5-4.7|

Other integrations

To view more documentation on integration options, please visit the Integration Options Documentation.

Moesif Middleware for .NET

Middleware SDK that captures incoming or outgoing API calls from .NET apps and sends to Moesif API Analytics.

Source Code on GitHub

How to install

Install the Nuget Package:

Install-Package Moesif.Middleware

This SDK supports both .NET Core 2.1 or higher and .NET Framework 4.5 or higher. Jump to installation for your specific framework:

Net Core installation

In Startup.cs file in your project directory, please add app.UseMiddleware&lt;MoesifMiddleware&gt;(moesifOptions); to the pipeline.

To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.

Add the middleware to your application:

using Moesif.Middleware;

public class Startup {

    // moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
    Dictionary<string, object> moesifOptions = new Dictionary<string, object>
    {
        {"ApplicationId", "Your Moesif Application Id"},
        {"LogBody", true},
        ...
        # For other options see below.
    };

    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {

        app.UseMiddleware<MoesifMiddleware>(moesifOptions);
        app.UseMvc();
    }
}

Your Moesif Application Id can be found in the Moesif Portal.
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging
into the Moesif Portal, click on the top-right menu,
and then clicking Installation.

.NET Core example

Checkout the examples
using .NET Core 2.0 and .NET Core 3.0

NET Framework installation

In Startup.cs file in your project directory, please add app.Use&lt;MoesifMiddleware&gt;(moesifOptions); to the pipeline.

To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.

Add the middleware to your application:

using Moesif.Middleware;

public class Startup {
    
    // moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
    Dictionary<string, object> moesifOptions = new Dictionary<string, object>
    {
        {"ApplicationId", "Your Moesif Application Id"},
        {"LogBody", true},
        ...
        # For other options see below.
    };

    public void Configuration(IAppBuilder app)
    {
        app.Use<MoesifMiddleware>(moesifOptions);
    }
}

Your Moesif Application Id can be found in the Moesif Portal.
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging
into the Moesif Portal, click on the top-right menu,
and then clicking Installation.

Add OWIN dependencies

IIS integrated pipeline

If you're running your .NET app on IIS (or Visual Studio IIS Express) using integrated mode (most common), you will have to install the OWIN SystemWeb package if not done so already:
Review OWIN Middleware in the IIS integrated pipeline for more info.

Install-Package Microsoft.Owin.Host.SystemWeb

Moesif does not support IIS running in Classic mode (Backwards compatibility for IIS 6.0). Unless your app predates IIS 6.0 and requires classic mode, you should switch to integrated mode.
{: .notice--primary}

Self-Host executable

While uncommon, if your application is a self-hosted executable that does not run on IIS, you may have to install the SelfHost package if not done so already:

For .NET Web API applications:

Install-Package Microsoft.AspNet.WebApi.OwinSelfHost

For all other .NET applications:

Install-Package Microsoft.Owin.SelfHost -Pre

.NET Framework Examples

The following examples are available for .NET Framework with Moesif:

Troubleshooting

Legacy website broken/Can I activate on API only?

If your .NET app is a traditional monolith consisting of both an API and website, you can choose to activate the middleware
on just your API only. Some legacy apps may have delicate and custom middleware chains.
An easy way to do that is via MapWhen:

    app.MapWhen(context => context.Request.Path.ToString().Contains("/api"), appBuilder =>
    {

        appBuilder.Use<MoesifMiddleware>(new System.Collections.Generic.Dictionary<string, object> {
            {"ApplicationId", "Your Moesif Application Id"}
        });
    });

How to test

  1. Manually clone the git repo
  2. From terminal/cmd navigate to the root directory of the middleware.
  3. Invoke 'Install-Package Moesif.Middleware'
  4. Add your own application id to 'Moesif.Middleware.Test/MoesifMiddlewareTest.cs'. You can find your Application Id from Moesif Dashboard -> Top Right Menu -> Installation
  5. The tests are contained in the Moesif.Middleware.Test project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.

Tested versions

Moesif has validated Moesif.Middleware against the following framework.

| | Framework Version |
| -------------- | ----------------- |
| .NET Core|2.0-3.0|
| .NET Framework MVC |4.5-4.7|
| .NET Framework Web API|4.5-4.7|
| .NET Framework Web API SelfHost|4.5-4.7|

Other integrations

To view more documentation on integration options, please visit the Integration Options Documentation.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.3 37 1/15/2021
1.3.2 105 1/9/2021
1.3.1 174 6/15/2020
1.3.0 84 6/15/2020
1.2.1 94 6/11/2020
1.1.6 161 6/9/2020
1.1.5 87 6/8/2020
1.1.4 122 6/8/2020
1.1.3 220 1/7/2020
1.1.2 154 12/19/2019
1.1.1 155 12/14/2019
1.1.0 148 11/15/2019
1.0.3 151 10/22/2019
1.0.2 154 8/27/2019
1.0.1 194 8/23/2019
0.2.2 188 6/26/2019
0.2.1 176 6/18/2019
0.2.0 199 5/30/2019
0.1.7 214 3/23/2019
0.1.6 229 3/1/2019
0.1.5 214 2/25/2019
0.1.4 219 2/25/2019
0.1.3 224 2/11/2019
0.1.1 245 11/19/2018
0.1.0 271 11/17/2018