I have web project using ASP.Net MVC. And, project structure is
- Libraries
- Core
- Data (I have used
AuditScope
to capture audit events to store them in sql that configured in web) - Services
- Presentation
- Web (I have a configuration class to use
SqlDataProvider
for Audit.Net) - Web Framework
- Web (I have a configuration class to use
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);
}
}