Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

LogEntry Information


#1

I have subscribed to the LogEntry event. Based on whether the LogEntryType is an Error, I have additional processing that I would like to do e.g. send the information to a notification processing system or whatever the case may be. In this particular case, I have invoked the LogException method, thus, the exception object was passed along for the ride. What I don’t see is how I get my hands on that information in the LogEntryEventArgs in order to send the information to the notification process.

Is there some way I can access this information?

Thanks,
Chad


#2

Hello,

Thanks for your posting. You can use the LogEntry property of the LogEntryEventArgs parameter to get access to the log entry that was just processed. The data of this log entry is made available via properties of the log entry object (e.g. SessionName, ThreadID, ProcessID etc). When you log a message with attached data (which is the case when using LogException), this data is made available with the Data property. Since SmartInspect can not only log and display text data but also binary, the Data property is a stream. In case of LogException, the Data property holds the textual representation of the exception, i.e. the exception message and the call stack.

In pseudo-code, your handler could like this:

[code]LogEntry logEntry = e.LogEntry;
if (logEntry.LogEntryType == error)
{
if (logEntry.Data != null)
{
// Read the Data property …
}

..

}[/code]

I hope this helps. Just let me know in case you have any further questions.

Kind regards,
Tobias


#3

Tobias,
Unfortunately, this is what I am doing. I am reading the stream from the data property. It’s 1474 bytes in length and they are all zeroes. I’m not sure why. I am logging the exception and in the console, when I click the log entry in the main window, I can see the exception stack trace in the viewer but it doesn’t appear to be making it into the LogEntryEventArgs properly or I am doing something wrong. I will continue to look on my end but if you could make sure there aren’t any issues with this, I would appreciate it.

Thanks,
Chad


#4

Chad,

Please make sure to reset the Stream by setting Position = 0 before reading it. This should do the trick.

Kind regards,
Tobias


#5

Tobias,
Excellent, that did the trick. So, why not handle setting the position to 0 on the Data property in the LogEntryEventArgs class in the setter perhaps? I’m not sure that it makes sense from a consumer’s perspective to have to remember or know to do that. Do you know what I mean?

This did the trick.

                e.LogEntry.Data.Position = 0;

                StreamReader reader = new StreamReader(e.LogEntry.Data);
                string text = reader.ReadToEnd();

Thanks again. I really appreciate the quick response.

Regards,
Chad


#6

Chad,

Yes, I understand what you mean and I agree that the stream should be reset by the library itself. I’ve just added it to our TODO list.

Thanks,
Tobias


#7

Tobias,
Thank you. Take care.

Chad