Pacem.Extensions.Logging.SqlServer 0.9.11

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.9.11
                    
NuGet\Install-Package Pacem.Extensions.Logging.SqlServer -Version 0.9.11
                    
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.9.11" />
                    
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.9.11" />
                    
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.9.11
                    
#r "nuget: Pacem.Extensions.Logging.SqlServer, 0.9.11"
                    
#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.9.11
                    
#: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.9.11
                    
Install as a Cake Addin
#tool nuget:?package=Pacem.Extensions.Logging.SqlServer&version=0.9.11
                    
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 net9.0 is compatible.  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.10.0-descartes 79 1/19/2026
0.10.0-cramer 84 1/13/2026
0.10.0-cotes 79 1/13/2026
0.10.0-clapeyron 80 1/12/2026
0.10.0-cauchy 81 1/12/2026
0.10.0-boyle 89 12/30/2025
0.10.0-abel 183 12/4/2025
0.9.14 564 12/1/2025
0.9.14-debroglie 170 11/26/2025
0.9.14-cantor 172 11/24/2025
0.9.14-bourbaki 169 11/24/2025
0.9.14-abel 145 11/23/2025
0.9.13 139 11/15/2025
0.9.12 151 11/15/2025
0.9.11 171 11/15/2025
0.9.1 178 10/23/2025
0.9.0 134 10/11/2025
0.9.0-fermi 178 9/29/2025
0.9.0-erlang 309 9/17/2025
0.9.0-dirac 82 8/2/2025
0.9.0-cayley 126 7/31/2025
0.9.0-boyle 125 7/31/2025
0.9.0-abel 190 7/17/2025
0.8.11 199 5/27/2025
0.8.10 180 5/7/2025
0.8.10-fourier 168 5/2/2025
0.8.10-fibonacci 235 2/7/2025
0.8.10-fermat 125 2/3/2025
0.8.10-euler 120 2/3/2025
0.8.10-euclid 132 2/1/2025
0.8.10-dalembert 127 1/31/2025
0.8.10-cauchy 129 1/26/2025
0.8.10-cantor 135 12/18/2024
0.8.10-caccioppoli 206 12/6/2024
0.8.10-bourbaki 130 12/6/2024
0.8.10-abel 150 4/22/2024
0.8.6 365 3/17/2024
0.8.6-abel 135 3/14/2024
0.8.5 193 3/13/2024
0.8.4 150 3/12/2024
0.8.3 170 3/12/2024
0.8.2 166 3/11/2024
0.8.1 156 3/11/2024