FormattedMessage is missing

Topics: Semantic Logging Application Block
Jan 8, 2014 at 3:21 PM
I have created a logger with an optional Message argument. Here is a typical set of logger methods:
        [Event(7, Message = "{0}", Level = EventLevel.Informational)]
        public void PutFoodJournalStart(string message = "")
        {
            message = "PUT FoodJournal() method call started at {0} UTC".FormatWith(SystemTime.Now());
            if (IsEnabled()) WriteEvent(7, message);
        }

        [Event(8, Message = "{0}", Level = EventLevel.Informational)]
        public void PutFoodJournalData(string sessionId, int personId, string data, string message = "")
        {
            message = "PUT FoodJournal() method data.";
            if (IsEnabled()) WriteEvent(8, sessionId, personId.ToString(), data, message);
        }

        [Event(9, Message = "{0}", Level = EventLevel.Informational)]
        public void PutFoodJournalEnd(string message = "")
        {
            message = "PUT FoodJournal() method call ended at {0} UTC".FormatWith(SystemTime.Now());
            if (IsEnabled()) WriteEvent(9, message);
        }
For some reason, the second method PutFoodJournalData will not write the Message to the FormattedMessage column. here's what I get instead:

FormattedMessage
PUT FoodJournal() method call ended at 1/8/2014 3:14:45 PM UTC
a313ee8f-cf66-4a92-b34c-c3e307d8d5d8
PUT FoodJournal() method call started at 1/8/2014 3:14:45 PM UTC
Jan 9, 2014 at 1:15 PM
The issue is that the the WriteEvent for PutFoodJournalData is not working because the expected parameter type for personId is Int32 but a string is being passed to WriteEvent (personId.ToString()).

If you run EventSourceAnalyzer.InspectAll(MyEventSource.Log) then an exception is thrown describing the error:
The parameter name 'personId' with type 'System.Int32' does not match the payload type 'System.String' in method 'PutFoodJournalData'. Check the parameter type in WriteEvent and assign a type that matches the same event arguement type .
To resolve the issue, remove the personId.ToString() call and just pass in personId.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by matthewpomar on 1/10/2014 at 8:54 AM
Jan 10, 2014 at 4:54 PM
Thank you Randy.