LogEvac 1.1.0
dotnet add package LogEvac --version 1.1.0
NuGet\Install-Package LogEvac -Version 1.1.0
<PackageReference Include="LogEvac" Version="1.1.0" />
<PackageVersion Include="LogEvac" Version="1.1.0" />
<PackageReference Include="LogEvac" />
paket add LogEvac --version 1.1.0
#r "nuget: LogEvac, 1.1.0"
#:package LogEvac@1.1.0
#addin nuget:?package=LogEvac&version=1.1.0
#tool nuget:?package=LogEvac&version=1.1.0
LogEvac

Automated log cleanup library for .NET applications using Serilog MSSQL sinks
Created by JayMar921
LogEvac is a lightweight .NET library that automatically removes old log records from SQL Server databases configured with Serilog MSSQL sinks. Perfect for keeping your logging database lean and performant without manual intervention.
📦 Quick Install
Choose your preferred installation method:
| Method | Command | .NET Version |
|---|---|---|
| .NET CLI | dotnet add package LogEvac --version 1.1.0 |
10 |
| NuGet Package Manager Console | Install-Package LogEvac -Version 1.1.0 |
10 |
| .csproj PackageReference | <PackageReference Include="LogEvac" Version="1.1.0" /> |
10 |
| .NET CLI | dotnet add package LogEvac --version 1.0.4 |
8 |
| NuGet Package Manager Console | Install-Package LogEvac -Version 1.0.4 |
8 |
| .csproj PackageReference | <PackageReference Include="LogEvac" Version="1.0.4" /> |
8 |
🔗 Example Project
Project-Serilog - Complete working reference implementation
This repository demonstrates:
- ✅ Full LogEvac integration setup
- ✅ Hangfire configuration with InMemoryStorage
- ✅ Serilog MSSQL sink configuration
- ✅ Dependency injection patterns
Perfect for: Getting started quickly or understanding integration patterns
📋 Table of Contents
- Features
- Prerequisites
- Installation & Dependencies
- Configuration
- Getting Started
- Configuration Options
- Example Project
- Troubleshooting
- License
✨ Features
- 🤖 Automated Cleanup: Schedule automatic log deletion based on age criteria
- ⚙️ Highly Configurable: Fine-tune cleanup frequency and retention periods (minutes, hours, days, weeks, or months)
- 🔧 Easy Integration: Simple extension methods for dependency injection
- 📊 Application-Specific: Target specific applications and environments
- 🔄 Hangfire Powered: Leverages Hangfire for reliable, persistent job scheduling
- 📈 Performance: Efficiently remove large batches of old logs without impacting database performance
📋 Prerequisites
- .NET 8.0 or later
- SQL Server (LocalDB, Express, Standard, or Enterprise)
- Serilog configured with MSSQL sink and ApplicationName column defined
- Hangfire already configured in your ASP.NET Core application
- Entity Framework Core 8.0 or later
📦 Installation & Dependencies
1. Add to Your Project
This library is designed to be integrated directly into your project. Add the source files to your ASP.NET Core application.
2. Required NuGet Dependencies
Ensure your project has these dependencies installed:
<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.0" />
<PackageReference Include="Hangfire.SqlServer" Version="1.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Serilog" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="6.5.0" />
</ItemGroup>
Quick Install via Package Manager Console:
Install-Package Hangfire.AspNetCore
Install-Package Hangfire.SqlServer
Install-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Serilog
Install-Package Serilog.Sinks.MSSqlServer
⚙️ Configuration
Step 1: Update appsettings.json
Add the logging connection string and LogEvac settings:
{
"ConnectionStrings": {
"LoggingDb": "Data Source=(localdb)\\MSSQLLocalDB;Integrated Security=true;Database=Logs"
},
"LogEvacSettings": {
"ApplicationName": "MyApplicationName",
"Environment": "Production",
"LoggingTable": "LogEvents",
"CheckingFrequencyInMinutes": 0,
"CheckingFrequencyInHours": 2,
"CleanUpDataOlderThanMinutesValue": 0,
"CleanUpDataOlderThanDaysValue": 0,
"CleanUpDataOlderThanWeeksValue": 0,
"CleanUpDataOlderThanMonthsValue": 1
}
}
Step 2: Reference appsettings.example.json
Use the included appsettings.example.json as a template for your environment-specific configurations.
🚀 Getting Started
Step 1: Configure Services in Program.cs
In your ASP.NET Core startup file, register LogEvac after Hangfire and Serilog:
// Setup Hangfire
builder.Services.AddHangfire(config => config.UseSqlServerStorage(hangfireConnection));
builder.Services.AddHangfireServer();
// Setup Serilog (with MSSQL sink)
builder.Host.UseSerilog((context, loggerConfig) =>
{
loggerConfig
.WriteTo.MSSqlServer(
connectionString: serilogConnection,
sinkOptions: new MSSqlServerSinkOptions { TableName = "Logs" }
);
});
// Initialize LogEvac
builder.InitializeLogEvac(); // Uses "LoggingDb" connection string by default
// OR use a custom connection string name:
// builder.InitializeLogEvac("LoggingDb-Local");
Step 2: Schedule the Cleanup Job
Before calling app.Run(), schedule the background job:
var app = builder.Build();
// ... other middleware configurations ...
app.ScheduleLogEvacJob(); // Starts the recurring cleanup job
app.Run();
🔧 Configuration Options
The LogEvacSettings section controls LogEvac behavior:
| Setting | Type | Default | Description |
|---|---|---|---|
ApplicationName |
string | - | Required. Application name to match in Serilog logs |
Environment |
string | - | Environment name (e.g., "Production", "Staging") |
LoggingTable |
string | "LogEvents" | Name of the logging table in the database |
CheckingFrequencyInMinutes |
int | 0 | Cleanup frequency in minutes (overrides hours if > 0) |
CheckingFrequencyInHours |
int | 2 | Cleanup frequency in hours (used if minutes is 0) |
CleanUpDataOlderThanMinutesValue |
int | 0 | Delete logs older than X minutes (overrides all if > 0) |
CleanUpDataOlderThanDaysValue |
int | 0 | Delete logs older than X days (overrides weeks/months if > 0) |
CleanUpDataOlderThanWeeksValue |
int | 0 | Delete logs older than X weeks (overrides months if > 0) |
CleanUpDataOlderThanMonthsValue |
int | 1 | Delete logs older than X months (default) |
Precedence Order (highest to lowest):
CleanUpDataOlderThanMinutesValueCleanUpDataOlderThanDaysValueCleanUpDataOlderThanWeeksValueCleanUpDataOlderThanMonthsValue
Example: Run Cleanup Every 30 Minutes, Delete Logs Older Than 7 Days
{
"LogEvacSettings": {
"ApplicationName": "MyApp",
"Environment": "Production",
"CheckingFrequencyInMinutes": 30,
"CleanUpDataOlderThanDaysValue": 7
}
}
🆘 Troubleshooting
❌ Scheduler Not Initialized
Problem: LogEvac services are not being initialized.
Solutions:
- Ensure
ConnectionStrings:LoggingDbis configured correctly inappsettings.json - Verify
LogEvacSettings:AppNameis not empty - Confirm Hangfire is configured before calling
InitializeLogEvac()
❌ No Logs Being Deleted
Problem: Cleanup job runs but doesn't delete logs.
Solutions:
- Check that the
ApplicationNamein settings matches the SerilogApplicationNamecolumn values - Verify the cleanup age criteria (minutes, days, weeks, or months) is set correctly
- Ensure the Serilog MSSQL sink has the
ApplicationNamecolumn in the logs table - Check Hangfire Dashboard to see job execution history and errors
❌ "Entity Framework" or "DbContext" Errors
Problem: Missing or misconfigured database context.
Solutions:
- Ensure
Microsoft.EntityFrameworkCore.SqlServeris installed - Verify connection string is valid and database exists
- Run
dotnet ef database updateif using migrations
❌ Connection String Not Found
Problem: Error referencing connection string key.
Solutions:
- Verify the connection string key exists in
appsettings.json - If using a custom key, ensure you pass it correctly:
builder.InitializeLogEvac("CustomKeyName") - Check for typos in connection string names
📝 License
This project was created by JayMar921.
Quick Reference
| Task | Command/Code |
|---|---|
| Install Dependencies | Install-Package Hangfire.AspNetCore Hangfire.SqlServer Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Serilog Serilog.Sinks.MSSqlServer |
| Register Services | builder.InitializeLogEvac(); |
| Schedule Job | app.ScheduleLogEvacJob(); |
| Use Custom DB | builder.InitializeLogEvac("MyCustomDbKey"); |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Hangfire (>= 1.8.23)
- Microsoft.EntityFrameworkCore (>= 10.0.9)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.