LoggingService.Extensions 1.0.2

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

📦 SpecMetrix Logging Integration Guide

This guide explains how to integrate centralized structured logging using the LoggingService.Extensions NuGet package and the LoggingServiceSetup.msi installer.


✅ Required Setup Steps

1. Install the Logging Service

Run the LoggingServiceSetup.msi to install and register the SpecMetrix Logging Windows Service.

  • This installs the logging API listener and background MongoDB writer.
  • It reads config from C:\Configurations\Specmetrix.json.

If you’re deploying to Linux or container-based environments, contact the team for the appropriate deployment strategy.


2. Install Required NuGet Packages

In your project:

dotnet add package LoggingService.Extensions
dotnet add package Serilog
dotnet add package Serilog.Sinks.Console
dotnet add package Serilog.Sinks.MongoDB
dotnet add package Serilog.Deduplication

🛠 Required Configuration

Your specmetrix.json must be placed at:

C:\Configurations\Specmetrix.json

And should include at least the following sections:

✅ Minimal Working Logging Configuration (with optional failover):

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.MongoDB" ],
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning",
        "LogSender": "Debug",
        "LogSender.*": "Debug"
      }
    },
    "WriteTo": [
      { "Name": "Console" },
      {
        "Name": "MongoDB",
        "Args": {
          "databaseUrl": "mongodb://localhost:27017/Logging",
          "collectionName": "Logs"
        }
      }
    ]
  },
  "Config": {
    "Logging": {
      "Deduplication": {
        "Error": {
          "DeduplicationEnabled": true,
          "DeduplicationWindowMilliseconds": 5000
        },
        "Warning": {
          "DeduplicationEnabled": true,
          "DeduplicationWindowMilliseconds": 3000
        },
        "Information": {
          "DeduplicationEnabled": true,
          "DeduplicationWindowMilliseconds": 1000
        },
        "Debug": {
          "DeduplicationEnabled": true,
          "DeduplicationWindowMilliseconds": 1000
        },
        "Verbose": {
          "DeduplicationEnabled": false,
          "DeduplicationWindowMilliseconds": 1000
        },
        "PruneIntervalMilliseconds": 60000,
        "CacheExpirationMilliseconds": 300000,
        "KeyProperties": [ "Code", "Source" ],
        "IncludeMessageTemplate": true
      }
    }
  },
  "Databases": {
    "LoggingMongoPrimary": {
      "Type": "MongoDb",
      "ConnectionString": "mongodb://localhost:27017",
      "DatabaseName": "Logging",
      "CollectionName": "Logs",
      "TimeField": "Timestamp",
      "MetaField": "metadata",
      "Granularity": "minutes",
      "ExpireAfterDays": 14
    },
    "LoggingMongoSecondary": {
      "Type": "MongoDb",
      "ConnectionString": "mongodb://backuphost:27017",
      "DatabaseName": "Logging",
      "CollectionName": "Logs",
      "TimeField": "Timestamp",
      "MetaField": "metadata",
      "Granularity": "minutes",
      "ExpireAfterDays": 14
    }
  },
  "LoggingRepositoryProfile": {
    "Primary": "LoggingMongoPrimary",
    "Secondary": "LoggingMongoSecondary", // Optional
    "Mode": "Failover" // Options: PrimaryOnly, Failover, DualWrite
  }
}

Secondary and Mode: Failover are optional. If omitted, only the Primary logging target will be used.


🧩 Program.cs Integration

In your project’s Program.cs, register the logging:

using LoggingService.Extensions;
using Serilog;

var builder = WebApplication.CreateBuilder(args);

// Register Serilog and structured logging pipeline
builder.Services.AddSpecMetrixLogging(builder.Configuration);
builder.Host.UseSerilog();

💉 Using the Logger in Your Service

Inject ILoggingService into your class, then call EnqueueLog(...) with structured values:

using LoggingService.Extensions.Interfaces;
using SpecMetrix.Interfaces;

public class UserService
{
    private readonly ILoggingService _logger;

    public UserService(ILoggingService logger)
    {
        _logger = logger;
    }

    public void ProcessUser(int userId)
    {
        _logger.EnqueueLog(new LogEntry
        {
            MessageTemplate = "Processed user {UserId}",
            TemplateValues = new Dictionary<string, object>
            {
                { "UserId", userId }
            },
            Level = LogLevel.Information,
            Namespace = "UserService",
            Source = "API",
            Code = "USR2001"
        });
    }
}

This will store structured log data in MongoDB, including metadata fields like Code, Source, Namespace, and others.


🚫 Do NOT Use Log.Information(...) Directly

Use the injected ILoggingService interface so that:

  • Logs are routed through deduplication and metadata enrichment
  • Your service stays decoupled from Serilog
  • Future routing (e.g., to different sinks or log processors) remains centralized

🧪 Testing & Troubleshooting

  • Verify the logging service is running as a Windows Service
  • Inspect Logs collection in MongoDB (Logging database)
  • Check Serilog output to Console for startup messages
  • Confirm specmetrix.json is correctly located in C:\Configurations

✅ Summary

Step What You Do
Install service Run LoggingServiceSetup.msi
Install NuGet packages Add LoggingService.Extensions and Serilog
Create Specmetrix.json Place in C:\Configurations\Specmetrix.json
Register in Program.cs Call AddSpecMetrixLogging(...)
Use logging Inject ILoggingService and call EnqueueLog()

Let the team know they can reach out if they need help integrating with non-.NET apps or want to stream logs into a centralized UI/dashboard.

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. 
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.2 146 4/1/2025
1.0.1 149 4/1/2025
1.0.0 140 4/1/2025