I am using Audit.Net EntityFramework data provider. This is my configuration in Startup.cs
Audit.Core.Configuration.Setup().UseEntityFramework(_ => _.AuditTypeMapper(t => typeof(AuditLog)).AuditEntityAction<AuditLog>((ev, entry, entity) =>
{
entity.AuditData = entry.ToJson();
entity.AuditDate = DateTime.Now;
entity.AuditUser = Environment.UserName;
// entity.AuditUsername = Environment.MachineName;
entity.AuditUsername = HttpContext.Current.User.Identity.Name;
})
.IgnoreMatchedProperties(true));
This is DBContext
public class DbContext : Audit.EntityFramework.AuditDbContext, IDbContext
{
public DbContext()
: base("DbContext")
{
Database.SetInitializer<DbContext>(null);
}
public Database GetDatabase()
{
return this.Database;
}
public new DbEntityEntry<T> Entry<T>(T entity) where T : class
{
return (new PContext().Entry(entity) as DbEntityEntry<T>);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
The problem only occurs when I change the value on a form or data table
The highlighted is the updated audit rec. All below are added and it seems it enters some kind of recursion since the first JSON record after the Update rec has 1281 characters, second 1146 , third 1763 ,4-th 2773 and so on until I stop the project.
at entity.AuditData = entry.ToJson();
getting this
System.OutOfMemoryException: 'Exception of type 'System.OutOfMemoryException' was thrown.'
What might be the problem?