AuditInfoEntity and Log4Net

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 09-Oct-2008 14:58:05   

I am building a simple Auditor based on the example in help. I'd like to use Log4Net as the persistence.

I assume AuditInfoEntity in the example is a table in a project somewhere that I don't need? ReSharper can't find it.

I would just add my Log4Net calls in each of the functions, such as AuditDeleteOfEntity and AuditDereferenceOfRelatedEntity etc?

Or

Would I create a simple in memory object and then when GetAuditEntitiesToSave is called, use Log4Net to persist the logs by iterating over the audit info?

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 09-Oct-2008 16:54:44   

I think I have solved it. I use in essence this for Log4Net interop:



    [DependencyInjectionInfo(typeof(IEntity2), "AuditorToUse")]
    [Serializable]
    public class GeneralAuditor : AuditorBase
    {
        private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public override void AuditDeleteOfEntity(IEntityCore entity)
        {
            Log.InfoFormat("Entity: {0} Action: Delete", entity.LLBLGenProEntityName);
        }

        public override void AuditDereferenceOfRelatedEntity(IEntityCore entity, IEntityCore relatedEntity, string mappedFieldName)
        {
            string info = string.Format("RelatedEntityName: {0}. MappedFieldName: {1}", relatedEntity.LLBLGenProEntityName, mappedFieldName);
            Log.InfoFormat("Entity: {0} Action: Reference Info: {1}", entity.LLBLGenProEntityName, info);
        }

        public override void AuditInsertOfNewEntity(IEntityCore entity)
        {
            Log.InfoFormat("Entity: {0} Action: InsertOfNewEntity", entity.LLBLGenProEntityName);
        }

        public override void AuditReferenceOfRelatedEntity(IEntityCore entity, IEntityCore relatedEntity, string mappedFieldName)
        {
            string info= string.Format("RelatedEntityName: {0}. MappedFieldName: {1}", relatedEntity.LLBLGenProEntityName, mappedFieldName);
            Log.InfoFormat("Entity: {0} Action: ReferenceOfRelatedEntity Info: {1}", entity.LLBLGenProEntityName,info);
        }

        public override void AuditUpdateOfExistingEntity(IEntityCore entity)
        {
            Log.InfoFormat("Entity: {0} Action: UpdateOfExistingEntity", entity.LLBLGenProEntityName);
        }

    }


Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Oct-2008 19:21:19   

I would just add my Log4Net calls in each of the functions, such as AuditDeleteOfEntity and AuditDereferenceOfRelatedEntity etc?

Or

Would I create a simple in memory object and then when GetAuditEntitiesToSave is called, use Log4Net to persist the logs by iterating over the audit info?

IMHO, both can work, but I favor the first approach (same as you did simple_smile ) which is the easier and most responsive.