Base solution for your next web application
Open Closed

Log changes made to model properties #858


User avatar
0
amirventer created

Hi,

I need to log all changes made to my models. I came across a library called FrameLog (<a class="postlink" href="https://bitbucket.org/MartinEden/framelog/wiki/Home">https://bitbucket.org/MartinEden/framelog/wiki/Home</a>) which does exactly what I need but I'm not sure how to plug it in.

It requires that I make the following changes to my DbContext:

public void Save(User author)
    {
        Logger.SaveChanges(author);
    }
    [Obsolete]
    public override int SaveChanges()
    {
        return base.SaveChanges();
    }

This won't work because boiler plate takes care of saving changes.

How can I hook into the SaveChanges method so that it can call Logger.SaveChanges(author);.

PS: Thanks for an awesome framework.

Regards, Amir


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You can override SaveChanges method in your dbcontext, since it's virtual. Remember to call base method after your custom code. Also override SaveChangesAsync and make same for it.