Browse Source

Refactored and fixed audit logging module

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
22e7c85d38
  1. 3
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogActionInfo.cs
  2. 6
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs
  3. 14
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs
  4. 14
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs
  5. 11
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs
  6. 18
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs
  7. 23
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs
  8. 10
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs
  9. 8
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs
  10. 1
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs
  11. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs
  12. 2
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs
  13. 51
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs
  14. 1
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs
  15. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs
  16. 8
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs
  17. 2
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs
  18. 2
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs
  19. 5
      modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs

3
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogActionInfo.cs

@ -1,10 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.Data;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Auditing namespace Volo.Abp.Auditing
{ {
public class AuditLogActionInfo : IMultiTenant public class AuditLogActionInfo : IMultiTenant, IHasExtraProperties
{ {
public Guid? TenantId { get; set; } public Guid? TenantId { get; set; }

6
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs

@ -2,11 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Volo.Abp.Data;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Auditing namespace Volo.Abp.Auditing
{ {
public class AuditLogInfo : IMultiTenant //TODO: Make serializable!
public class AuditLogInfo : IMultiTenant, IHasExtraProperties
{ {
public Guid? UserId { get; set; } public Guid? UserId { get; set; }
@ -34,6 +36,8 @@ namespace Volo.Abp.Auditing
public List<EntityChangeInfo> EntityChanges { get; } public List<EntityChangeInfo> EntityChanges { get; }
public List<string> Comments { get; set; }
public AuditLogInfo() public AuditLogInfo()
{ {
Actions = new List<AuditLogActionInfo>(); Actions = new List<AuditLogActionInfo>();

14
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs

@ -1,11 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using Volo.Abp.Data;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Auditing namespace Volo.Abp.Auditing
{ {
public class EntityChangeInfo : IMultiTenant public class EntityChangeInfo : IMultiTenant, IHasExtraProperties
{ {
public DateTime ChangeTime { get; set; } public DateTime ChangeTime { get; set; }
@ -19,11 +19,13 @@ namespace Volo.Abp.Auditing
public List<EntityPropertyChangeInfo> PropertyChanges { get; set; } public List<EntityPropertyChangeInfo> PropertyChanges { get; set; }
#region Not mapped public Dictionary<string, object> ExtraProperties { get; }
[NotMapped] public virtual object EntityEntry { get; set; } //TODO: Try to remove since it breaks serializability
public virtual object EntityEntry { get; set; } //TODO: ???
#endregion public EntityChangeInfo()
{
ExtraProperties = new Dictionary<string, object>();
}
} }
} }

14
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogActionConsts.cs

@ -1,13 +1,11 @@
using System; namespace Volo.Abp.AuditLogging
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.AuditLogging
{ {
public class AuditLogActionConsts public class AuditLogActionConsts
{ {
public static int MaxServiceNameLength = 256; public const int MaxServiceNameLength = 256;
public static int MaxMethodNameLength = 256;
public static int MaxParametersLength = 1024; public const int MaxMethodNameLength = 128;
public const int MaxParametersLength = 2000;
} }
} }

11
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs

@ -2,9 +2,12 @@
{ {
public static class AuditLogConsts public static class AuditLogConsts
{ {
public static int MaxClientIpAddressLength = 64; public const int MaxClientIpAddressLength = 64;
public static int MaxClientNameLength = 128;
public static int MaxBrowserInfoLength = 512; public const int MaxClientNameLength = 128;
public static int MaxExceptionsLength = 8*1024;
public const int MaxBrowserInfoLength = 512;
public const int MaxExceptionsLength = 4000;
} }
} }

18
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs

@ -9,12 +9,12 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging namespace Volo.Abp.AuditLogging
{ {
public class AuditLog : Entity<Guid>, IHasExtraProperties, IMultiTenant public class AuditLog : AggregateRoot<Guid>, IHasExtraProperties, IMultiTenant
{ {
public virtual Guid? TenantId { get; protected set; }
public virtual Guid? UserId { get; protected set; } public virtual Guid? UserId { get; protected set; }
public virtual Guid? TenantId { get; protected set; }
public virtual Guid? ImpersonatorUserId { get; protected set; } public virtual Guid? ImpersonatorUserId { get; protected set; }
public virtual Guid? ImpersonatorTenantId { get; protected set; } public virtual Guid? ImpersonatorTenantId { get; protected set; }
@ -29,13 +29,13 @@ namespace Volo.Abp.AuditLogging
public virtual string BrowserInfo { get; protected set; } public virtual string BrowserInfo { get; protected set; }
public virtual string Exceptions { get; set; } public virtual string Exceptions { get; protected set; }
public Dictionary<string, object> ExtraProperties { get; set; } public virtual Dictionary<string, object> ExtraProperties { get; protected set; }
public ICollection<EntityChange> EntityChanges { get; } public virtual ICollection<EntityChange> EntityChanges { get; protected set; }
public ICollection<AuditLogAction> Actions { get; protected set; } public virtual ICollection<AuditLogAction> Actions { get; protected set; }
protected AuditLog() protected AuditLog()
{ {
@ -54,10 +54,10 @@ namespace Volo.Abp.AuditLogging
BrowserInfo = auditInfo.BrowserInfo; BrowserInfo = auditInfo.BrowserInfo;
ImpersonatorUserId = auditInfo.ImpersonatorUserId; ImpersonatorUserId = auditInfo.ImpersonatorUserId;
ImpersonatorTenantId = auditInfo.ImpersonatorTenantId; ImpersonatorTenantId = auditInfo.ImpersonatorTenantId;
ExtraProperties = auditInfo.ExtraProperties; ExtraProperties = auditInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
EntityChanges = auditInfo.EntityChanges.Select(e => new EntityChange(guidGenerator, Id, e)).ToList(); EntityChanges = auditInfo.EntityChanges.Select(e => new EntityChange(guidGenerator, Id, e)).ToList();
Actions = auditInfo.Actions.Select(e => new AuditLogAction(guidGenerator.Create(), Id, e)).ToList(); Actions = auditInfo.Actions.Select(e => new AuditLogAction(guidGenerator.Create(), Id, e)).ToList();
Exceptions = String.Join(Environment.NewLine, auditInfo.Exceptions.Select(e=>e.ToString()).ToArray()); Exceptions = auditInfo.Exceptions.JoinAsString(Environment.NewLine);
} }
} }
} }

23
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs

@ -1,13 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging namespace Volo.Abp.AuditLogging
{ {
public class AuditLogAction : Entity<Guid>, IHasExtraProperties public class AuditLogAction : Entity<Guid>, IMultiTenant, IHasExtraProperties
{ {
public Guid? TenantId { get; protected set; }
public virtual Guid AuditLogId { get; protected set; } public virtual Guid AuditLogId { get; protected set; }
public virtual string ServiceName { get; protected set; } public virtual string ServiceName { get; protected set; }
@ -21,22 +25,23 @@ namespace Volo.Abp.AuditLogging
public virtual int ExecutionDuration { get; protected set; } public virtual int ExecutionDuration { get; protected set; }
public virtual Dictionary<string, object> ExtraProperties { get; protected set; } public virtual Dictionary<string, object> ExtraProperties { get; protected set; }
protected AuditLogAction() protected AuditLogAction()
{ {
ExtraProperties = new Dictionary<string, object>(); ExtraProperties = new Dictionary<string, object>();
} }
public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo auditLogActionInfo) public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo)
{ {
Id = id; Id = id;
TenantId = actionInfo.TenantId;
AuditLogId = auditLogId; AuditLogId = auditLogId;
ServiceName = auditLogActionInfo.ServiceName; ServiceName = actionInfo.ServiceName;
MethodName = auditLogActionInfo.MethodName; MethodName = actionInfo.MethodName;
Parameters = auditLogActionInfo.Parameters; Parameters = actionInfo.Parameters;
ExecutionTime = auditLogActionInfo.ExecutionTime; ExecutionTime = actionInfo.ExecutionTime;
ExecutionDuration = auditLogActionInfo.ExecutionDuration; ExecutionDuration = actionInfo.ExecutionDuration;
ExtraProperties = auditLogActionInfo.ExtraProperties; //TODO: Copy, instead of assign ExtraProperties = actionInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
} }
} }
} }

10
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs

@ -2,13 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging namespace Volo.Abp.AuditLogging
{ {
public class EntityChange : Entity<Guid>, IMultiTenant public class EntityChange : Entity<Guid>, IMultiTenant, IHasExtraProperties
{ {
public virtual Guid AuditLogId { get; protected set; } public virtual Guid AuditLogId { get; protected set; }
@ -24,9 +25,11 @@ namespace Volo.Abp.AuditLogging
public ICollection<EntityPropertyChange> PropertyChanges { get; protected set; } public ICollection<EntityPropertyChange> PropertyChanges { get; protected set; }
public virtual Dictionary<string, object> ExtraProperties { get; protected set; }
protected EntityChange() protected EntityChange()
{ {
ExtraProperties = new Dictionary<string, object>();
} }
public EntityChange(IGuidGenerator guidGenerator, Guid auditLogId, EntityChangeInfo entityChangeInfo) public EntityChange(IGuidGenerator guidGenerator, Guid auditLogId, EntityChangeInfo entityChangeInfo)
@ -38,7 +41,8 @@ namespace Volo.Abp.AuditLogging
ChangeType = entityChangeInfo.ChangeType; ChangeType = entityChangeInfo.ChangeType;
EntityId = entityChangeInfo.EntityId; EntityId = entityChangeInfo.EntityId;
EntityTypeFullName = entityChangeInfo.EntityTypeFullName; EntityTypeFullName = entityChangeInfo.EntityTypeFullName;
PropertyChanges = entityChangeInfo.PropertyChanges.Select( p=> new EntityPropertyChange(guidGenerator, Id, p)).ToList(); PropertyChanges = entityChangeInfo.PropertyChanges.Select(p => new EntityPropertyChange(guidGenerator, Id, p)).ToList();
ExtraProperties = entityChangeInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
} }
} }
} }

8
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs

@ -2,11 +2,14 @@
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AuditLogging namespace Volo.Abp.AuditLogging
{ {
public class EntityPropertyChange : Entity<Guid> public class EntityPropertyChange : Entity<Guid>, IMultiTenant
{ {
public Guid? TenantId { get; protected set; }
public virtual Guid EntityChangeId { get; protected set; } public virtual Guid EntityChangeId { get; protected set; }
public virtual string NewValue { get; protected set; } public virtual string NewValue { get; protected set; }
@ -24,8 +27,9 @@ namespace Volo.Abp.AuditLogging
public EntityPropertyChange(IGuidGenerator guidGenerator, Guid entityChangeId, EntityPropertyChangeInfo entityChangeInfo) public EntityPropertyChange(IGuidGenerator guidGenerator, Guid entityChangeId, EntityPropertyChangeInfo entityChangeInfo)
{ {
EntityChangeId = entityChangeId;
Id = guidGenerator.Create(); Id = guidGenerator.Create();
TenantId = entityChangeInfo.TenantId;
EntityChangeId = entityChangeId;
NewValue = entityChangeInfo.NewValue; NewValue = entityChangeInfo.NewValue;
OriginalValue = entityChangeInfo.OriginalValue; OriginalValue = entityChangeInfo.OriginalValue;
PropertyName = entityChangeInfo.PropertyName; PropertyName = entityChangeInfo.PropertyName;

1
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs

@ -5,5 +5,6 @@ namespace Volo.Abp.AuditLogging
{ {
public interface IAuditLogRepository : IBasicRepository<AuditLog, Guid> public interface IAuditLogRepository : IBasicRepository<AuditLog, Guid>
{ {
} }
} }

4
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingDbContext.cs

@ -13,10 +13,6 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
public DbSet<AuditLog> AuditLogs { get; set; } public DbSet<AuditLog> AuditLogs { get; set; }
public DbSet<AuditLogAction> AuditLogAction { get; set; }
public DbSet<EntityChange> EntityChange { get; set; }
public AbpAuditLoggingDbContext(DbContextOptions<AbpAuditLoggingDbContext> options) public AbpAuditLoggingDbContext(DbContextOptions<AbpAuditLoggingDbContext> options)
: base(options) : base(options)
{ {

2
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreModule.cs

@ -12,8 +12,6 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{ {
context.Services.AddAbpDbContext<AbpAuditLoggingDbContext>(options => context.Services.AddAbpDbContext<AbpAuditLoggingDbContext>(options =>
{ {
options.AddDefaultRepositories<IAuditLoggingDbContext>();
options.AddRepository<AuditLog, EfCoreAuditLogRepository>(); options.AddRepository<AuditLog, EfCoreAuditLogRepository>();
}); });

51
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs

@ -21,9 +21,11 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
builder.Entity<AuditLog>(b => builder.Entity<AuditLog>(b =>
{ {
b.ToTable(tablePrefix + "AuditLogs", schema); b.ToTable(tablePrefix + "AuditLogs", schema);
b.ConfigureExtraProperties();
b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress)); b.Property(x => x.ClientIpAddress).HasMaxLength(AuditLogConsts.MaxClientIpAddressLength).HasColumnName(nameof(AuditLog.ClientIpAddress));
b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName)); b.Property(x => x.ClientName).HasMaxLength(AuditLogConsts.MaxClientNameLength).HasColumnName(nameof(AuditLog.ClientName));
b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo)); b.Property(x => x.BrowserInfo).HasMaxLength(AuditLogConsts.MaxBrowserInfoLength).HasColumnName(nameof(AuditLog.BrowserInfo));
b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionsLength).HasColumnName(nameof(AuditLog.Exceptions)); b.Property(x => x.Exceptions).HasMaxLength(AuditLogConsts.MaxExceptionsLength).HasColumnName(nameof(AuditLog.Exceptions));
b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration)); b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLog.ExecutionDuration));
@ -32,18 +34,36 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.Property(x => x.UserId).HasColumnName(nameof(AuditLog.UserId)); b.Property(x => x.UserId).HasColumnName(nameof(AuditLog.UserId));
b.Property(x => x.TenantId).HasColumnName(nameof(AuditLog.TenantId)); b.Property(x => x.TenantId).HasColumnName(nameof(AuditLog.TenantId));
b.ConfigureExtraProperties();
b.HasMany<AuditLogAction>().WithOne().HasForeignKey(x => x.AuditLogId); b.HasMany<AuditLogAction>().WithOne().HasForeignKey(x => x.AuditLogId);
b.HasMany<EntityChange>().WithOne().HasForeignKey(x => x.AuditLogId); b.HasMany<EntityChange>().WithOne().HasForeignKey(x => x.AuditLogId);
b.HasIndex(x => new { x.TenantId, x.ExecutionTime });
b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime }); b.HasIndex(x => new { x.TenantId, x.UserId, x.ExecutionTime });
}); });
builder.Entity<AuditLogAction>(b =>
{
b.ToTable(tablePrefix + "AuditLogActions", schema);
b.ConfigureExtraProperties();
b.Property(x => x.AuditLogId).HasColumnName(nameof(AuditLogAction.AuditLogId));
b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength).HasColumnName(nameof(AuditLogAction.ServiceName));
b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength).HasColumnName(nameof(AuditLogAction.MethodName));
b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters));
b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime));
b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration));
b.HasIndex(x => new { x.AuditLogId });
b.HasIndex(x => new { x.TenantId, x.ServiceName, x.MethodName, x.ExecutionTime });
});
builder.Entity<EntityChange>(b => builder.Entity<EntityChange>(b =>
{ {
b.ToTable(tablePrefix + "EntityChanges", schema); b.ToTable(tablePrefix + "EntityChanges", schema);
b.ConfigureExtraProperties();
b.Property(x => x.EntityTypeFullName).IsRequired().HasColumnName(nameof(EntityChange.EntityTypeFullName)); b.Property(x => x.EntityTypeFullName).IsRequired().HasColumnName(nameof(EntityChange.EntityTypeFullName));
b.Property(x => x.EntityId).IsRequired().HasColumnName(nameof(EntityChange.EntityId)); b.Property(x => x.EntityId).IsRequired().HasColumnName(nameof(EntityChange.EntityId));
b.Property(x => x.AuditLogId).IsRequired().HasColumnName(nameof(EntityChange.AuditLogId)); b.Property(x => x.AuditLogId).IsRequired().HasColumnName(nameof(EntityChange.AuditLogId));
@ -53,7 +73,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.HasMany<EntityPropertyChange>().WithOne().HasForeignKey(x => x.EntityChangeId); b.HasMany<EntityPropertyChange>().WithOne().HasForeignKey(x => x.EntityChangeId);
b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName}); b.HasIndex(x => new { x.AuditLogId });
b.HasIndex(x => new { x.TenantId, x.EntityTypeFullName, x.EntityId });
}); });
builder.Entity<EntityPropertyChange>(b => builder.Entity<EntityPropertyChange>(b =>
@ -65,26 +86,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.Property(x => x.PropertyTypeFullName).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyTypeFullName)); b.Property(x => x.PropertyTypeFullName).IsRequired().HasColumnName(nameof(EntityPropertyChange.PropertyTypeFullName));
b.Property(x => x.OriginalValue).HasColumnName(nameof(EntityPropertyChange.OriginalValue)); b.Property(x => x.OriginalValue).HasColumnName(nameof(EntityPropertyChange.OriginalValue));
b.HasIndex(x => new { x.PropertyName}); b.HasIndex(x => new { x.EntityChangeId });
});
builder.Entity<AuditLogAction>(b =>
{
b.ToTable(tablePrefix + "AuditLogActions", schema);
b.Property(x => x.ServiceName).HasMaxLength(AuditLogActionConsts.MaxServiceNameLength).HasColumnName(nameof(AuditLogAction.ServiceName));
b.Property(x => x.MethodName).HasMaxLength(AuditLogActionConsts.MaxMethodNameLength).HasColumnName(nameof(AuditLogAction.MethodName));
b.Property(x => x.Parameters).HasMaxLength(AuditLogActionConsts.MaxParametersLength).HasColumnName(nameof(AuditLogAction.Parameters));
b.Property(x => x.AuditLogId).HasColumnName(nameof(AuditLogAction.AuditLogId));
b.Property(x => x.ExecutionTime).HasColumnName(nameof(AuditLogAction.ExecutionTime));
b.Property(x => x.ExecutionDuration).HasColumnName(nameof(AuditLogAction.ExecutionDuration));
b.ConfigureExtraProperties();
b.HasIndex(x => new { x.ServiceName, x.ExecutionTime});
}); });
} }
} }
} }

1
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs

@ -9,6 +9,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
public EfCoreAuditLogRepository(IDbContextProvider<IAuditLoggingDbContext> dbContextProvider) public EfCoreAuditLogRepository(IDbContextProvider<IAuditLoggingDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
} }
} }
} }

4
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/IAuditLoggingDbContext.cs

@ -8,9 +8,5 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
public interface IAuditLoggingDbContext : IEfCoreDbContext public interface IAuditLoggingDbContext : IEfCoreDbContext
{ {
DbSet<AuditLog> AuditLogs { get; set; } DbSet<AuditLog> AuditLogs { get; set; }
DbSet<AuditLogAction> AuditLogAction { get; set; }
DbSet<EntityChange> EntityChange { get; set; }
} }
} }

8
modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpSettingManagementMongoDbContextExtensions.cs → modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbContextExtensions.cs

@ -1,13 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
namespace Volo.Abp.AuditLogging.MongoDB namespace Volo.Abp.AuditLogging.MongoDB
{ {
public static class AbpSettingManagementMongoDbContextExtensions public static class AbpAuditLoggingMongoDbContextExtensions
{ {
public static void ConfigureSettingManagement( public static void ConfigureAuditLogging(
this IMongoModelBuilder builder, this IMongoModelBuilder builder,
Action<MongoModelBuilderConfigurationOptions> optionsAction = null) Action<MongoModelBuilderConfigurationOptions> optionsAction = null)
{ {
@ -19,7 +17,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
builder.Entity<AuditLog>(b => builder.Entity<AuditLog>(b =>
{ {
b.CollectionName = options.CollectionPrefix + "Settings"; b.CollectionName = options.CollectionPrefix + "AuditLogging";
}); });
} }
} }

2
modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs

@ -14,8 +14,6 @@ namespace Volo.Abp.AuditLogging.MongoDB
context.Services.AddMongoDbContext<AuditLoggingMongoDbContext>(options => context.Services.AddMongoDbContext<AuditLoggingMongoDbContext>(options =>
{ {
options.AddDefaultRepositories<IAuditLoggingMongoDbContext>();
options.AddRepository<AuditLog, MongoAuditLogRepository>(); options.AddRepository<AuditLog, MongoAuditLogRepository>();
}); });

2
modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AuditLoggingMongoDbContext.cs

@ -15,7 +15,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
{ {
base.CreateModel(modelBuilder); base.CreateModel(modelBuilder);
modelBuilder.ConfigureSettingManagement(options => modelBuilder.ConfigureAuditLogging(options =>
{ {
options.CollectionPrefix = CollectionPrefix; options.CollectionPrefix = CollectionPrefix;
}); });

5
modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs

@ -17,6 +17,7 @@ namespace Volo.Abp.AuditLogging
[Fact] [Fact]
public async Task Should_Save_A_Audit_Log() public async Task Should_Save_A_Audit_Log()
{ {
//Arrange
var auditLog = new AuditLogInfo() var auditLog = new AuditLogInfo()
{ {
TenantId = Guid.NewGuid(), TenantId = Guid.NewGuid(),
@ -30,7 +31,11 @@ namespace Volo.Abp.AuditLogging
BrowserInfo = "Chrome" BrowserInfo = "Chrome"
}; };
//Act
await _auditingStore.SaveAsync(auditLog); await _auditingStore.SaveAsync(auditLog);
//Assert
//TODO:...
} }
} }
} }

Loading…
Cancel
Save