Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3336002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:05:03+00:00 2026-05-18T00:05:03+00:00

i’ve hooked up logging in my application to automatically log changes to certain entities

  • 0

i’ve hooked up logging in my application to automatically log changes to certain entities using event listeners. This works great but for some of the properties withing the entities i’m logging i don’t wish to insert a log if only a change is made to that property. These properties are decorated with the IgnoreLoggingAttribute attribute. Here is what i have so far:

public void OnPostUpdate(PostUpdateEvent @event)
{
    var session = @event.Session.GetSession(NHibernate.EntityMode.Poco);

    if (@event.Entity is User)
        session.SaveOrUpdate(new UserLog((User)@event.Entity));
    ...
}

The @event exposes 2 properties which are called State and OldState. I can use this to check for changes however i can’t pull out the properties i’m interested in since these are simply an object arrays. I figured i could use some reflection to get the all the indexes (for any properties with the IgnoreLoggingAttribute) and match them up with the ones in the object array. So far i have come up with:

var properties = typeof(User).GetProperties().Where(p => p.GetCustomAttributes(typeof(IgnoreLoggingAttribute), false).Count() > 0);

The problem now is it doesn’t give me the index of the property against the original entity. I also need to make sure this matches the appropriate index from the @event.State and @event.OldState properties (which both seem to ignore certain properties).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:05:03+00:00Added an answer on May 18, 2026 at 12:05 am

    I was able to achieve this by calling this method before inserting into the log table:

    private bool IsDirty(PostUpdateEvent @event) {
        // Get all the mapped property names
        var propertyNames = @event.Session.Factory.GetClassMetadata(@event.Entity.GetType()).PropertyNames;
    
        // Get the property index to ignore
        var propertyIndexesToIgnore = @event.Entity.GetType().GetProperties()
            .Where(p => p.GetCustomAttributes(typeof(IgnoreLoggingAttribute), false).Count() > 0)
            .Select(p => Array.IndexOf(propertyNames, p.Name)).ToArray();
    
        if (@event.OldState != null && @event.State != null) {
            for (var i = 0; i < @event.OldState.Length; i++) {
                if (!propertyIndexesToIgnore.Contains(i) && !@event.OldState[i].Equals(@event.State[i]))
                    return true;
            }
        }
    
        return false;
    }
    

    Now all i have to do is apply the IgnoreLoggingAttribute attribute to any properties i don’t wish to log. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.