ByteGuard.SecurityLogger.AspNetCore 1.0.1

Prefix Reserved
dotnet add package ByteGuard.SecurityLogger.AspNetCore --version 1.0.1
                    
NuGet\Install-Package ByteGuard.SecurityLogger.AspNetCore -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByteGuard.SecurityLogger.AspNetCore" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ByteGuard.SecurityLogger.AspNetCore" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ByteGuard.SecurityLogger.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ByteGuard.SecurityLogger.AspNetCore --version 1.0.1
                    
#r "nuget: ByteGuard.SecurityLogger.AspNetCore, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ByteGuard.SecurityLogger.AspNetCore@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ByteGuard.SecurityLogger.AspNetCore&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ByteGuard.SecurityLogger.AspNetCore&version=1.0.1
                    
Install as a Cake Tool

ByteGuard.SecurityLogger.AspNetCore NuGet Version

ByteGuard.SecurityLogger.AspNetCore adds ASP.NET Core-aware logging methods on top of ByteGuard.SecurityLogger.

It exposes the same OWASP Logging Vocabulary event methods as the core package, but with an HttpContext-based variant suffixed with FromHttp (e.g. LogAuthnLoginSuccessFromHttp(...)). These methods use HttpContext to automatically populate the logging scope fields according to the OWASP Logging Vocabulary format and the SecurityEventMetadata model in the core package

Getting Started

Installation

This package is published and installed via NuGet.

Reference the package in your project:

dotnet add package ByteGuard.SecurityLogger.AspNetCore

Usage

Log your security events and populate the security event metadata from the HttpContext:

public class MyClass
{
    private readonly IHttpContextAccessor _httpContextAccessor;
    private readonly ILogger<MyController> _logger;

    public MyClass(
        IHttpContextAccessor httpContextAccessor,
        ILogger<MyController> logger)
    {
        _logger = logger;
        _httpContextAccessor = httpContextAccessor
    }

    public void MyFunction()
    {
        // Create configuration instance
        var config = new SecurityLoggerConfiguration
        {
            AppId = "MyApp"
        };

        // Create security logger instance
        var securityLogger = _logger.AsSecurityLogger(config);

        // Log you security event
        var userId = //...
        securityLogger.AuthnLoginSuccessFromHttp(
            "User {UserId} successfully logged in.",
            userId: userId,
            httpContext, _httpContextAccessor.HttpContext
            args: user.Id
        );

        // ...
    }
}

Populated properties

The following properties of the SecurityEventMetadata are populated via the HttpContext:

  • UserAgent
  • SourceIp
  • HostIp
  • Hostname
  • Protocol
  • Port
  • RequestUri
  • RequestMethod

These map into the same structured scope keys that the core package uses via the SecurityEventMetadata class, so your logs remain consistent whether you log from HTTP requests or from background services.

Predefined values in metadata

FromHttp methods are avaiable in two variants:

  • One that only uses the HttpContext to populate metadata
  • Ont that additionally accepts a predefined SecurityEventMetadata

When you pass a SecurityEventMetadata instance, any values you set explicitly take precedence over values derived from HttpContext. Only missing metadata fields will be filled from the HTTP request.

Example

var securityEventMetadata = new SecurityEventMetadata
{
    Hostname = "my-custom-host.com"
}

// Assume: HttpContext.Request.Host = "my-host.com"

securityLogger.LogAuthnSuccessFromHttp(
    "User {UserId} successfully logged in.",
    userId: userId,
    httpContext: HttpContext,
    metadata: securityEventMetadata,
    args: userId
);

// Resulting scope/metadata includes:
// - Hostname = "my-custom-host.com" (your value wins)
// - Other fields may still be populated from HttpContext (source IP, URI, method, etc.)

Reverse proxies and real client IPs

If your app runs behind a reverse proxy / load balancer, HttpContext.Connection.RemoteIpAddress may reflect the proxy rather than the real client.

If you want accurate client IPs, ensure your app is configured to process forwarded headers (common in production hosting setups). The FromHttp methods can only log the IP that ASP.NET Core exposes to the app.

Supported events

All events supported by the core ByteGuard.SecurityLogger is also supported by the ByteGuard.SecurityLogger.AspNetCore extensions package. All supported events can be seen in the WIKI

License

ByteGuard.SecurityLogger.AspNetCore is Copyright © ByteGuard Contributors - Provided under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 34 12/30/2025
1.0.0 39 12/30/2025
1.0.0-dev-01002 31 12/30/2025