Hello, We are using AspNetZero (Paid) Product version --> 4.0 Product type --> MVC Product framework type --> .net core
We want to disable logging each and every event happening in system. We only want to log exceptions. Reason: It seems to be affecting system performance significantly.
Please do let us know if there is a way to do so via some configuration changes or any other way?
4 Answer(s)
-
0
Hi,
You can implement your own AuditingStore similar to https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Zero.Common/Auditing/AuditingStore.cs and save audit log only if
auditInfo.Exception
is not null. -
0
As @ismcagdas suggested, you can implement your own AuditStore. What we did was create an admin setting that we could use to log only errors or log all events This is what our implementation looks like:
public class SmcAuditStore : AuditingStore { public ILogger<AuditingStore> Logger { get; set; } private readonly IRepository<AuditLog, long> _auditLogRepository; private readonly ISettingManager _settingManager; public SmcAuditStore(IRepository<AuditLog, long> auditLogRepository, ISettingManager settingManager) : base(auditLogRepository) { _auditLogRepository = auditLogRepository; _settingManager = settingManager; } public override async Task SaveAsync(AuditInfo auditInfo) { AuditLog auditLog = new AuditLog(); bool logErrorsOnly = await _settingManager.GetSettingValueAsync<bool>(AppSettings.Logging.LogOnErrorsOnly); var exceptionMessage = auditInfo.Exception != null ? auditInfo.Exception.ToString() : null; if ((logErrorsOnly && exceptionMessage != null) || !logErrorsOnly) { auditLog = await _auditLogRepository.InsertAsync(AuditLog.CreateFromAuditInfo(auditInfo)); } } }
You can replace the default auditstore by replacing it in the Core Module PreInitialize:
Configuration.ReplaceService<IAuditingStore, SmcAuditStore>();
-
0
Thanks @cmthomps for sharing this. Such a setting would be good for AspNet Zero I guess :).
-
1
@ismcagdas - It would be a nice feature!