I need to perform some kind of auditing. We want to store when a record is inserted, updated, removed or opened.
For now I have created a simple method on a Singleton class:
public void Audit(string audit, AuditTypes type)
{
AuditEntry = new AuditEntry(){ Audit = audit, TypeId = (int)type };
// some logic to commit the audit entry to the database
}
public enum AuditTypes
{
Insert = 1,
Update = 2,
Delete = 3
Open = 4
}
Somewhere in the forms I call this method:
MyForm.cs:
private void RemoveSomeObject(SomeObject myObject)
{
/* Do some stuff that removes the object*/
MySingleton.GetInstance().Audit(myObject.Title, AuditTypes.Delete)
}
For some reason, I don't think this is the way to go because using this approach everywhere in the code I have this kind of lines.
I think it is smarter to do it a more OO way, what do you think? EDIT:
I do log the User id and date, but I didn't find it relevant to notice.