Skip to content
No description, website, or topics provided.
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Helpful.Logging.Owin.Test.Integration
Helpful.Logging.Owin
TestApplication
.gitattributes
.gitignore
Helpful.Logging.Owin.sln
README.md

README.md

Helpful.Logging.Owin

This is Owin middleware for the Helpful.Logging logging context which allows you to automatically populate the logging context from http headers of received calls.

##Usage

public void Configuration(IAppBuilder appBuilder)
{
    var config = new HttpConfiguration();

    config.MapHttpAttributeRoutes();

    appBuilder.Use<LoggingContextMiddleware>(new Dictionary<string, Func<string>> { { "correlation-id", () => Guid.NewGuid().ToString()}});
    appBuilder.UseWebApi(config);
}

The above configuration will look for an HTTP header named correlation-id and add the value of that header to every log entry made as a result of that request. If the header is not found or it is empty, it will use a new guid as the value.

There is also the option to log all request and response payloads automatically while log4net is logging in DEBUG. To configure this, the above becomes:

public void Configuration(IAppBuilder appBuilder)
{
    var config = new HttpConfiguration();

    config.MapHttpAttributeRoutes();

    appBuilder.Use<LoggingContextMiddleware>(new Dictionary<string, Func<string>> { { "testheader", () => "default value"}})
                .Use<DebugTrafficLoggingMiddleware>()
                .UseWebApi(config);
}

##Install Install-Package Helpful.Logging.Owin

##Note This is tightly coupled to log4net - if you don't use this, it's no use to you.

You can’t perform that action at this time.