1

I have web project using ASP.Net MVC. And, project structure is

  1. Libraries
    • Core
    • Data (I have used AuditScope to capture audit events to store them in sql that configured in web)
    • Services
  2. Presentation
    • Web (I have a configuration class to use SqlDataProvider for Audit.Net)
    • Web Framework

The above settings not working as in the Data project AuditScope didn't recognize SqlDataProvider. I believe it happened because Data layer project didn't aware of the registration in Web project. If so, how to configure this?

Here below, I have attached code to configure and capture audit event what i used.

Configuration Class:

public static class AuditNetRegistrar
{
    public static void Register()
    {
        Configuration.Setup()
            .UseSqlServer(config => config
                            .ConnectionString(System.Configuration.ConfigurationManager.ConnectionStrings["masterConnection"].ToString())
                            .Schema("Audit")
                            .IdColumnName("EventId")
                            .JsonColumnName("JsonData")
                            .LastUpdatedColumnName("LastUpdatedDate")
                            .CustomColumn("EventType", ev => ev.EventType)
                            .CustomColumn("User", ev => ev.Environment.UserName)
                            .TableName("General"));
    }
}

Startup Class: (Web)

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        AuditNetRegistrar.Register();
        .
        .
        .
        .
    }
}

Repository Class: (Data)

public void InsertUserProfile(UserProfile userProfile)
{
    using (var audit = AuditScope.Create("UserProfile:Insert", () => userProfile))
    {
        _dbContext.Insert(userProfile);
    }
}
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44

1 Answers1

0

Probably a bit late but also need this nugget package to write to SQL from Audit.net

https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.NET.SqlServer/README.md

Gavin Mannion
  • 875
  • 1
  • 14
  • 32