Audit Trail Component , .net standard 2.1 + Full Source Code Download


Audit Trail Component , .net standard 2.1 + Full Source Code Download

Audit Path Element + Full Supply Code

Model v1.0



Audit path element shops database actions (Add, Replace, Delete), enterprise actions (you’ll be able to specify them), sends notifications and logs its personal errors, additionally it’s dynamic because it provides consumer the flexibility to specify [Business actions], [Emails that notifications will be sent to], [Notification’s subject] and [Notification’s Message], additionally you’ll be able to seek for all the information has been saved by the element by predefined strategies.

Framework: .web normal 2.1

Packages :

  • Microsoft.EntityFrameworkCore.SqlServer 3.1.3
  • Newtonsoft.Json  12.0.3

Hangfire Packages :

  • Hangfire.AspNetCore
  • Hangfire.SqlServer

Options :

  • Retailer database actions and enterprise actions.
  • Ship notifications.
  • Log ship notification course of, and retry if it’s failed.
  • Log errors.
  • Dynamic: Consumer can specify actions and emails and specify if the element ought to ship notification when a selected motion occurred.

Advice :

use background job to execute element strategies, to make sure that the unique request time won’t be elevated.


Database Tables


to retailer actions lookup information


to make relation between [action], and emails, so if this motion occurred then the element will   ship notification to the associated emails with the required message.


to retailer the audit information


to log the element errors


to retailer the notifications that the element will ship to emails


to log the ship notification course of, element will retailer each (ship electronic mail) retry and retailer if it’s completed efficiently or not with error message


Learn how to Register


  • In your venture, you must set up Hangfire nugetpackages [Hangfire.AspNetCore, Hangfire.SqlServer] ,or any bundle to carry out background processing.
  • Additionally you must implement[ IEmailService ] interface to ship notification emails .


Startup class

  • In methodology [ConfigureServices]

        #area hangfire

            // Add Hangfire companies.

            companies.AddHangfire(configuration => configuration




                .UseSqlServerStorage(Configuration.GetConnectionString(“DefaultConnection”), new SqlServerStorageOptions


                    CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),

                    SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),

                    QueuePollInterval = TimeSpan.Zero,

                    UseRecommendedIsolationLevel = true,

                    UsePageLocksOnDequeue = true,

                    DisableGlobalLocks = true



            // Add the processing server as IHostedService





            #area Audit

            companies.AddScoped<IEmailService, EmailService>();


            //AddAuditTrail courses


                 new Listing<AuditActionDto> {

                    new AuditActionDto() { ActionCode =”CreateOrder”,SendNotification=true,NotificationFromEmail=”

                                        ,NotificationEmails=”,”,NotificationSubject=”topic “

                                        ,NotificationMessage=”pattern message”},

                    new AuditActionDto() { ActionCode = “DeleteOrder”,SendNotification=true,NotificationFromEmail=””,

  NotificationEmails=”,”,NotificationSubject=”topic “  ,

   NotificationMessage=”pattern message2” },

                    new AuditActionDto() { ActionCode = “UpdateOrder” ,SendNotification=true},

                   new AuditActionDto() { ActionCode = “NewUpdateOrder” ,SendNotification=false}});



            //register background job to Test Notifications to ship emails

            var sp = companies.BuildServiceProvider().CreateScope().ServiceProvider;

            var notificationService = sp.GetService<INotificationPublicService>();

                 JobStorage.Present = new SqlServerStorage(Configuration.GetConnectionString(“DefaultConnection”),

                 new SqlServerStorageOptions


                CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),

                SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),

                QueuePollInterval = TimeSpan.Zero,

                UseRecommendedIsolationLevel = true,

                UsePageLocksOnDequeue = true,

                DisableGlobalLocks = true


            RecurringJob.AddOrUpdate(() => notificationService.CheckNotificationsAndSend(), Cron.Each day);



Learn how to create tables

  • Open [Package manager console] and within the [Default project] listing .. choose [AuditTrailComponent] venture
  • Write the under instructions
    • add-migration InitiatAudit -context AuditDbContext
    • update-database -context AuditDbContext


Learn how to use


  • Inject this interface to your class [IAuditTrailService]
  • To retailer enterprise motion

BackgroundJob.Enqueue(() => AuditTrailService.SaveCustomActionsAuditTrailAsync(“DeleteOrder”, “pattern information by hangfire”, “username1”));


  • To retailer database motion ,use the under code earlier than Entity framework save modifications methodology

BackgroundJob.Enqueue(() =>AuditTrailService.SaveDbActionsAuditTrailAsync(ApplicationDbContext.ChangeTracker.Entries()

            .Choose(a =>

            new DatabaseChangesDto


                Entity = a.Entity,

                OriginalValues = a.OriginalValues.ToObject(),

                CurrentValues = a.CurrentValues.ToObject()



  • To seek for audit information

//Inject this interface [IAuditTrailService]

AuditTrailFilterDto mannequin = new AuditTrailFilterDto {Audit_ActionCode=”DeleteOrder” };

var consequence=await AuditTrailService.Search(mannequin);


  • To seek for Notifications

//Inject this interface [INotificationPublicService]

NotificationFilterDto mannequin = new NotificationFilterDto { Audit_ActionCode=”DeleteOrder” };

var consequence=await NotificationPublicService.SearchNotifications(mannequin);


  • to seek for notification log

//Inject this interface [IErrorLogPublicService]

NotificationLogFilterDto mannequin = new NotificationLogFilterDto { };

 var consequence = await NotificationService.SearchNotificationLogs(mannequin);


  • to seek for error logs

//Inject this interface [IErrorLogPublicService]

ErrorLogFilterDto model4 = new ErrorLogFilterDto();

var consequence = await ErrorLogPublicService.Search(model4);






Be the first to comment

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.