Pacem.Extensions.Logging.SqlServer 0.8.10-fermat

This is a prerelease version of Pacem.Extensions.Logging.SqlServer.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Pacem.Extensions.Logging.SqlServer --version 0.8.10-fermat
                    
NuGet\Install-Package Pacem.Extensions.Logging.SqlServer -Version 0.8.10-fermat
                    
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="Pacem.Extensions.Logging.SqlServer" Version="0.8.10-fermat" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pacem.Extensions.Logging.SqlServer" Version="0.8.10-fermat" />
                    
Directory.Packages.props
<PackageReference Include="Pacem.Extensions.Logging.SqlServer" />
                    
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 Pacem.Extensions.Logging.SqlServer --version 0.8.10-fermat
                    
#r "nuget: Pacem.Extensions.Logging.SqlServer, 0.8.10-fermat"
                    
#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 Pacem.Extensions.Logging.SqlServer@0.8.10-fermat
                    
#: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=Pacem.Extensions.Logging.SqlServer&version=0.8.10-fermat&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pacem.Extensions.Logging.SqlServer&version=0.8.10-fermat&prerelease
                    
Install as a Cake Tool

SqlServer Logging Extensions

⚗️ ==Experimental==

⚠️ Experimental libs are discouraged to use in production.

About

Pacem.Extensions.Loggin.SqlServer provides extensions to store your logs into a Sql Server database.

The following paragraphs exemplify the library utilization given common use cases.

How to

Add the relevant logger provider to the logging builder (e.g. ILoggingBuilder).

First, define the target entity.
Exploit DataAnnotation like in attribute-based entity definitions (if you're familiar with EntityFramework Core).

ℹ️ Please notice:

  • TableAttribute is recommended to correctly identify the target table.
    Fallback, in case of missing attribute, is dbo.<LogEntityTypeName>.
  • ColumnAttribute is mandatory in case of name mismatch between property and column, but optional otherwise.

If you want to ignore a property, decorate it with a NotMappedAttribute.

// Structure of a log row in the [Logging].[Logs] table in the database
[Table("Logs", Schema = "Logging")]
public class MyLogEntity
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity), Key]
    public int Id { get; set; }

    [Required]
    public required string Source { get; set; }

    [Required]
    public required string Message { get; set; }

    [Column(TypeName = "tinyint")]
    public LogLevel LogLevel { get; set; }

    [Column(TypeName = "datetimeoffset(3)")]
    public DateTimeOffset Timestamp { get; set; }

    public string? ErrorMessage { get; set; }

    public string? ErrorStack { get; set; }

    public string? AllData { get; set; }

    /// <summary>
    /// Some relation to the business logic world "outside", if any.
    /// </summary>
    public Guid? RelationId { get; set; }
}

Then, configure the logger provider:

// Program.cs
builder.Logging.AddPacemSqlServerLogging<MyLogEntity>(
    "sql-server-connectionstring-here",
    // mapper log line -> log entity
    log =>
    {
        if (!log.Name.StartsWith("Pacem."))
        {
            // by returning null you skip the log
            return null;
        }
        Guid? relationId = default;
        if (log.Data?.TryGetValue("relation", out var relationObj) == true
        && Guid.TryParse(relationObj?.ToString(), out Guid result))
        {
            relationId = result;
        }
        return new MyLogEntity
        {
            Source = log.Name,
            Timestamp = log.Timestamp,
            Message = log.Message,
            ErrorMessage = log.Exception?.Message,
            ErrorStack = log.Exception?.StackTrace,
            LogLevel = log.LogLevel,
            AllData = JsonSerializer.Serialize(log.Data),
            RelationId = relationId
        };
    });

Plans for version next

Multiple entities log.

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
0.9.0-erlang 272 9/17/2025
0.9.0-dirac 60 8/2/2025
0.9.0-cayley 105 7/31/2025
0.9.0-boyle 104 7/31/2025
0.9.0-abel 142 7/17/2025
0.8.11 179 5/27/2025
0.8.10 161 5/7/2025
0.8.10-fourier 148 5/2/2025
0.8.10-fibonacci 216 2/7/2025
0.8.10-fermat 109 2/3/2025
0.8.10-euler 104 2/3/2025
0.8.10-euclid 110 2/1/2025
0.8.10-dalembert 109 1/31/2025
0.8.10-cauchy 111 1/26/2025
0.8.10-cantor 117 12/18/2024
0.8.10-caccioppoli 189 12/6/2024
0.8.10-bourbaki 109 12/6/2024
0.8.10-abel 126 4/22/2024
0.8.6 346 3/17/2024
0.8.6-abel 116 3/14/2024
0.8.5 174 3/13/2024
0.8.4 134 3/12/2024
0.8.3 149 3/12/2024
0.8.2 149 3/11/2024
0.8.1 139 3/11/2024