DatabaseEasyLog 1.0.0
See the version list below for details.
dotnet add package DatabaseEasyLog --version 1.0.0
NuGet\Install-Package DatabaseEasyLog -Version 1.0.0
<PackageReference Include="DatabaseEasyLog" Version="1.0.0" />
paket add DatabaseEasyLog --version 1.0.0
#r "nuget: DatabaseEasyLog, 1.0.0"
// Install DatabaseEasyLog as a Cake Addin #addin nuget:?package=DatabaseEasyLog&version=1.0.0 // Install DatabaseEasyLog as a Cake Tool #tool nuget:?package=DatabaseEasyLog&version=1.0.0
dblogger (easyLog)
DB Context Logger independent of the database driver.
History
We decided to use MySql in our company for our database provider. Once we needed to log anything that changed at the entity we cannot use some stuff like temporal table or something else. So we developed a similar framework to log changes to the entity the easiest way.
Description
This framework is an easy way to log any entity changes by the dbContext whether you added, modified or deleted an entity.
Your project should be structured according to the repository pattern. Your repository just needs to inherit from the interface ILogRepository
.
Once you configured everthing its very easy to log your changes.
How to use
inherit from RepositoryBase
in your repository
The repository should inherit by the interface ILogRepository
. The interface contains two Methods:
SaveChangesWithLog(Guid? userId, Cancellationtoken token)
This method will save any changes at your entity which are tracked by the ef core changetracker. The userId should be this one who changed the entity. if there is no userId given, the log entry will saved it as a system changed event.
SaveChangesWithLog(Guid? userId, IReadOnlyList<strings> propertiesToIgnore, Cancellationtoken token)
This method is similar to the first one but you can give the method a list of property names which will not be logged from your entity.
Configuration
First things first. Before we can use the framework, we have to create a migration-script and configure the entity model-builder. Your migration-script and model-builder which you have to created should look like this:
public void Configure(EntityTypeBuilder<LogEntry> builder)
{
builder.ToTable("Logs");
}
You have to use the entity LogEntry
migrationBuilder.CreateTable(
name: "Logs",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "utf8mb4_unicode_ci"),
ContextId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "utf8mb4_unicode_ci"),
Context = table.Column<string>(type: "longtext", nullable: false, collation: "utf8mb4_unicode_ci").Annotation("MySql:CharSet", "utf8mb4"),
Property = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, collation: "utf8mb4_unicode_ci").Annotation("MySql:CharSet", "utf8mb4"),
PreviousValue = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, collation: "utf8mb4_unicode_ci").Annotation("MySql:CharSet", "utf8mb4"),
CurrentValue = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, collation: "utf8mb4_unicode_ci").Annotation("MySql:CharSet", "utf8mb4"),
ChangedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
ChangedBy = table.Column<Guid>(type: "char(36)", nullable: true, collation: "utf8mb4_unicode_ci"),
LogType = table.Column<string>(type: "varchar(10)", maxLength: 255, nullable: true, collation: "utf8mb4_unicode_ci") .Annotation("MySql:CharSet", "utf8mb4"),
LogTypeBy = table.Column<string>(type: "varchar(10)", maxLength: 255, nullable: true, collation: "utf8mb4_unicode_ci") .Annotation("MySql:CharSet", "utf8mb4"),
Revision = table.Column<int>(type: "int", maxLength: 10, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Logs", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4")
.Annotation("Relational:Collation", "utf8mb4_unicode_ci");
How to create an entry
You can use booth methods if your repository inherits the interface ILogRepository.
Result
Once you create a LogEntry, your table should look like this:
Happy logging
Thanks to sami for the support
visit our company traperto
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.