pvNugsLoggerNc6Abstractions 6.0.0

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

pvNugsLoggerNc6Abstractions

A comprehensive .NET 6 logging framework that provides structured, contextual logging with support for multiple output destinations, user contexts, and typed logging capabilities.

Features

  • Multiple Output Destinations: Support for console, SQL, and hybrid logging configurations
  • Contextual Logging: Track user, company, and topic contexts across log entries
  • Structured Logging: Detailed metadata for each log entry including machine name, method name, and line numbers
  • Severity Levels: Comprehensive severity level system compatible with Microsoft's LogLevel
  • Method Result Tracking: Built-in support for tracking method execution results and notifications
  • Base Implementation: Ready-to-use abstract base class for creating custom logging implementations
  • Async Support: Both synchronous and asynchronous logging methods
  • Unit Testing Support: Specialized interfaces for testing logging behavior

Installation

Install via NuGet Package Manager:

Install-Package pvNugsLoggerNc6Abstractions

Or via .NET CLI:

dotnet add package pvNugsLoggerNc6Abstractions

Core Components

Logger Services

  • ILoggerService: The main logging interface that provides comprehensive logging functionality
  • BaseLoggerService: Abstract base class implementing ILoggerService with core functionality
  • IConsoleLoggerService: Specialized service for console output
  • IHybridLoggerService: Combines multiple logging outputs
  • IUTestLoggerService: Specialized service for unit testing scenarios

Log Writers

  • ILogWriter: Base interface for writing log entries to various destinations
  • IConsoleLogWriter: Specialized writer for console output
  • IUTestLogWriter: Writer with additional capabilities for testing scenarios

Method Results

  • IMethodResult: Tracks method execution status and notifications
  • IMethodResultNotification: Represents individual notifications within results

Data Structures

  • ILoggerServiceRow: Represents a structured log entry with metadata
  • SeverityEnu: Defines available logging severity levels
  • SqlRoleEnu: Defines SQL database access roles

Basic Usage

Using Existing Implementations

public class ExampleService
{
    private readonly ILoggerService _logger;

    public ExampleService(ILoggerService logger)
    {
        _logger = logger;
    }

    public async Task DoSomethingAsync()
    {
        // Set context for subsequent log entries
        _logger.SetUser("user123", "company456");
        _logger.SetTopic("ImportantOperation");

        try
        {
            // Log a simple message
            _logger.Log("Starting operation", SeverityEnu.Info);

            // Perform some work...

            // Log multiple messages
            await _logger.LogAsync(
                new[] { "Step 1 complete", "Step 2 complete" },
                SeverityEnu.Debug);
        }
        catch (Exception ex)
        {
            // Log exception with context
            await _logger.LogAsync(ex);
            throw;
        }
    }
}

Creating Custom Implementations

public class CustomLoggerService : BaseLoggerService
{
    public CustomLoggerService(SeverityEnu minLevel, params ILogWriter[] logWriters)
        : base(minLevel, logWriters)
    {
    }

    // BaseLoggerService provides all the core functionality
    // Override specific methods if needed for custom behavior
}

public class CustomLogWriter : ILogWriter
{
    public void WriteLog(string? userId, string? companyId, string? topic,
        SeverityEnu severity, string machineName, string memberName,
        string filePath, int lineNumber, string message, DateTime dateUtc)
    {
        // Implement your custom log writing logic
    }

    public async Task WriteLogAsync(string? userId, string? companyId, string? topic,
        SeverityEnu severity, string machineName, string memberName,
        string filePath, int lineNumber, string message, DateTime dateUtc)
    {
        // Implement your custom async log writing logic
        await Task.CompletedTask;
    }

    public void Dispose() { }
    public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}

Unit Testing

public class LoggingTests
{
    private readonly IUTestLogWriter _logWriter;
    private readonly IUTestLoggerService _logger;

    [Fact]
    public void ShouldLogError()
    {
        _logger.Log("Test error", SeverityEnu.Error);

        Assert.True(_logWriter.Contains("Test error"));
        var logEntry = _logWriter.FindLastMatchingRow("Test error");
        Assert.Equal(SeverityEnu.Error, logEntry.Severity);
    }
}

Available Implementations

This abstractions package provides the foundation for logging. For ready-to-use implementations, consider these companion packages:

  • pvNugsLoggerNc6MsSql: SQL Server logging implementation
  • pvNugsLoggerNc6Serilog: Serilog integration implementation

Microsoft.Extensions.Logging Integration

The BaseLoggerService implements Microsoft.Extensions.Logging.ILogger interface, making it fully compatible with .NET 6's built-in logging framework and dependency injection container.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 (9)

Showing the top 5 NuGet packages that depend on pvNugsLoggerNc6Abstractions:

Package Downloads
pvNugsLoggerNc6UTest

A lightweight in-memory logging implementation for unit testing in .NET 6 applications. Captures log entries in memory for easy verification in unit tests with search and query capabilities.

pvNugsSecretManagerNc6Azure

Package Description

pvNugsLoggerNc6Hybrid

Package Description

pvNugsCacheNc6Local

High-performance in-memory caching solution for .NET 6 applications. Built on Microsoft.Extensions.Caching.Memory, it provides thread-safe cache operations with configurable TTL, integrated logging, and async/await support. Simple dependency injection setup for local caching needs.

pvNugsCsProviderNc6MsSql

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 197 11/13/2025

Initial