SimpleLogAuditingStore.cs 925 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Threading.Tasks;
  2. using Castle.Core.Logging;
  3. namespace Abp.Auditing
  4. {
  5. /// <summary>
  6. /// Implements <see cref="IAuditingStore"/> to simply write audits to logs.
  7. /// </summary>
  8. public class SimpleLogAuditingStore : IAuditingStore
  9. {
  10. /// <summary>
  11. /// Singleton instance.
  12. /// </summary>
  13. public static SimpleLogAuditingStore Instance { get; } = new SimpleLogAuditingStore();
  14. public ILogger Logger { get; set; }
  15. public SimpleLogAuditingStore()
  16. {
  17. Logger = NullLogger.Instance;
  18. }
  19. public Task SaveAsync(AuditInfo auditInfo)
  20. {
  21. if (auditInfo.Exception == null)
  22. {
  23. Logger.Info(auditInfo.ToString());
  24. }
  25. else
  26. {
  27. Logger.Warn(auditInfo.ToString());
  28. }
  29. return Task.FromResult(0);
  30. }
  31. }
  32. }