AKS.Sql.Logger



The AKS.Sql.Logger NuGet package (version 1.1.5) is a lightweight logging utility designed for .NET 8 applications, enabling developers to log application events and exceptions directly into a SQL Server database.


Key Features

  • SQL Logging: Logs are stored in a SQL Server table named Logs, which includes columns for timestamp, log level, category, message, and exception details.

  • .NET 8 Compatibility: Fully compatible with .NET 8.0 and computed to work with .NET 9.0 and various platform-specific targets like Android, iOS, macOS, and Windows.

  • Simple Integration: Provides two primary methods: Log() for general messages and LogException() for capturing exceptions.


🧱 Setup Instructions

  1. Install the Package:

    Using the .NET CLI:


    dotnet add package AKS.Sql.Logger --version 1.1.5

  1. Create the Logs Table:

    Execute the following SQL script in your database:


    CREATE TABLE Logs ( Id INT IDENTITY(1,1) PRIMARY KEY, Timestamp DATETIME, LogLevel NVARCHAR(50), Category NVARCHAR(100), Message NVARCHAR(MAX), Exception NVARCHAR(MAX) NULL );

  1. Implement in Your .NET Application:


    using Microsoft.Extensions.Logging; using AKS.Sql.Logger; var logger = new AKSSqlLogger("MyAppCategory", "Server=YOUR_SERVER;Database=YOUR_DB;Trusted_Connection=True;TrustServerCertificate=True;"); logger.Log(LogLevel.Information, "Operation completed successfully."); try { // Your code logic here } catch (Exception ex) { logger.LogException(LogLevel.Error, ex); }


📦 Dependencies


For more details or to download the package, visit the AKS.Sql.Logger NuGet page.

Comments

Popular posts from this blog