Anyware.Shared.Logging 2.0.0

dotnet add package Anyware.Shared.Logging --version 2.0.0
                    
NuGet\Install-Package Anyware.Shared.Logging -Version 2.0.0
                    
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="Anyware.Shared.Logging" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anyware.Shared.Logging" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Anyware.Shared.Logging" />
                    
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 Anyware.Shared.Logging --version 2.0.0
                    
#r "nuget: Anyware.Shared.Logging, 2.0.0"
                    
#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 Anyware.Shared.Logging@2.0.0
                    
#: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=Anyware.Shared.Logging&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Anyware.Shared.Logging&version=2.0.0
                    
Install as a Cake Tool

Anyware.Shared.Logging

Anyware.Shared.Logging is the shared .NET 8 logging package for Anyware services. It provides one-line logging setup with date-based rolling files, optional console output, structured context fields, retention cleanup, and a bounded async Serilog pipeline.

Install

After publishing to the private feed:

dotnet add package Anyware.Shared.Logging --version 0.3.0-preview

0.3.0-preview adds the audit logger feature (IAuditLogger, AuditEvent, AddAnywareAuditLogger()). See "Audit logging" below.

Services must consume this as a NuGet package, not a project reference.

For full publishing steps, see Publishing.

Usage

using Anyware.Shared.Logging;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseAnywareFileLogging("crm");

var app = builder.Build();
app.Run();

Optional request context:

using (Anyware.Shared.Logging.LoggerContextExtensions.PushAnywareLogContext(
    correlationId: "corr-1",
    tenantId: "tenant-1",
    userId: "user-1"))
{
    logger.LogInformation("Contact created {ContactId}", contactId);
}

For a complete consuming-service setup, see Usage Guide.

How It Works

The package wires Serilog into the host through UseAnywareFileLogging. Configuration is read from Logging:Anyware, translated into strongly typed options, and used to build a bounded async logging pipeline. The custom DateRollingFileSink writes UTF-8 records to one service log file per local day. When Logging:Anyware:Console:Enabled is true, the same formatted lines are also written to standard output. LogCleanerHostedService removes old files on a background timer.

The implementation is documented in System Implementation.

Configuration

{
  "Logging": {
    "Anyware": {
      "Path": "./logs",
      "FileName": "crm",
      "MinimumLevel": "Information",
      "Format": "Pretty",
      "Retention": {
        "Enabled": true,
        "RetentionDays": 14,
        "CleanerIntervalHours": 24
      },
      "Async": {
        "QueueCapacity": 10000,
        "BlockWhenFull": false
      },
      "Console": {
        "Enabled": false
      }
    }
  }
}

Build and Test

From this folder:

dotnet restore
dotnet build .\Anyware.Shared.Logging.sln
dotnet test .\Anyware.Shared.Logging.sln
dotnet pack .\Anyware.Shared.Logging.csproj -c Release -o .\artifacts

Documentation

Audit logging (since 0.3.0-preview)

Services that mutate platform state can record audit events through IAuditLogger. The default implementation forwards each event as a structured Information log entry; future package versions can swap in a Kafka/Elastic shipping sink without callers changing.

using Anyware.Shared.Logging;

builder.Services.AddAnywareAuditLogger();   // registers IAuditLogger
public sealed class SettingsAdminApplicationService(IAuditLogger audit, ...)
{
    public async Task SetValueAsync(...)
    {
        // ... succeed in the domain ...
        await audit.LogAsync(new AuditEvent
        {
            Action      = "settings.value.set",
            ActorUserId = currentUser.UserId,
            TenantId    = currentUser.TenantId,
            TargetType  = "setting_value",
            TargetId    = definitionId.ToString(),
            Before      = beforeJson,
            After       = afterJson,
            CorrelationId = currentUser.CorrelationId,
            OccurredAt    = DateTimeOffset.UtcNow,
            RedactPayload = definition.IsSecret,    // replaces Before/After with "<redacted>"
        });
    }
}

Rules:

  • Emit one audit event per successful state mutation. Failed/aborted handlers MUST NOT emit.
  • Always set RedactPayload = true for secret-flagged data; the implementation handles the replacement.
  • Use the <service>.<resource>.<action> convention for the Action field (e.g. iam.user.deactivated, settings.value.set).
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 was computed.  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 was computed.  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
2.0.0 425 5/7/2026
0.2.2-preview 106 5/4/2026
0.2.0-preview 115 4/29/2026