2

So I'm using SLAB and I have a Database listener logging out to a database. I'm testing with a single method on the event source. The issue that I'm having is that the log is being inserted into the database just as I want it, but I'm also getting an exception log before every entry

enter image description here In my output window, it says exactly the same thing, "EventSourceException". I'm having a hard time figuring out what the exception is let alone how to fix it.

Here is the event source method:

[Event(2, Message = "ACCESS_ADMIN",
    Level = EventLevel.LogAlways,
    Keywords = Keywords.AdminAccess)]
public void LogAdminAccess(string userInfo, string resource, string clientIpAddress, bool succeeded)
{
    SetCurrentThreadActivityId(GetNewActivityId());
    WriteEventWithRelatedActivityId(2, GetRequestId(), userInfo, resource, clientIpAddress, succeeded);
}

This is how the listener is being initialized, inproc:

var dbSemanticLogListener = SqlDatabaseLog.CreateListener(
    "MyComponent",
    PayliteRegistry.MainDatabaseConnectionString);

dbSemanticLogListener.EnableEvents(
   AprivaPciAuditEventSource.Log,
   EventLevel.LogAlways, 
    MyEnum.Keywords.AccountModified |
    MyEnum.Keywords.AdminAccess |
    MyEnum.Keywords.DatabaseAccess |
    MyEnum.Keywords.ApplicationStateChange);

And the call to the logger:

MyLoggerClass.Log.LogAdminAccess(
    userInfo, 
    request.RequestUri.AbsolutePath, 
    request.GetClientIpAddress(), 
    true);

Any ideas on what the problem could be or at least how to get to the actual exception being thrown?

Other bits not shown

  • This EventSource class is sealed
  • I've stepped through and verified that the methods GetNewActivityId() and GetRequestId() are not throwing the exception
  • The exception shows up in the output window when WriteEventWithRelatedActivityId(... is executed but the exception isn't bubbling up; it appears to be handled in the base class.
Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176

1 Answers1

3

It turns out, that

  • I'm using related activity ids for something other than what they were intended
  • In order for it to work, you must specify an EventOpCode in the event attribute.
Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
  • Did you find the root cause of this issue? Can't say for sure, but it seems that I had started having the same issue when calling WriteEventWithRelatedActivityId after installing new runtime. – Refraction Nov 10 '15 at 09:11
  • The root cause was that I wasn't using it correctly. The related activity id is intended for relating *threads* back to their parent threads. But if you're going to use it at all, you have to specify an EventOpCode. Simply specifying that got it to work for me. – Sinaesthetic Nov 10 '15 at 17:22
  • Thank you for reply. All our events are marked with this attribute. I tried to reproduce the issue that I have on machine with 4.5 runtime - everything is ok. So seems that it is caused by 4.6 – Refraction Nov 13 '15 at 14:03