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
<PackageReference Include="Anyware.Shared.Logging" Version="2.0.0" />
<PackageVersion Include="Anyware.Shared.Logging" Version="2.0.0" />
<PackageReference Include="Anyware.Shared.Logging" />
paket add Anyware.Shared.Logging --version 2.0.0
#r "nuget: Anyware.Shared.Logging, 2.0.0"
#:package Anyware.Shared.Logging@2.0.0
#addin nuget:?package=Anyware.Shared.Logging&version=2.0.0
#tool nuget:?package=Anyware.Shared.Logging&version=2.0.0
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
- Architecture
- Configuration
- Public API
- Usage Guide
- Log Format
- Testing
- Operations
- Publishing
- System Implementation
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 = truefor secret-flagged data; the implementation handles the replacement. - Use the
<service>.<resource>.<action>convention for theActionfield (e.g.iam.user.deactivated,settings.value.set).
| Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Serilog (>= 4.3.0)
- Serilog.Extensions.Hosting (>= 8.0.0)
- Serilog.Sinks.Async (>= 2.1.0)
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 |