EventSources not picked up by out-of-process listener

Topics: Semantic Logging Application Block
Sep 2, 2013 at 2:05 PM
Hi All

Scenario:
Web application that has its own event source "WebEvents". Also, referenced assemblies have their respective event sources, for example "CachingEvents".

Problem: Only events logged by "WebEvents" gets picked up by the out-of-process listener - the IsEnabled() calls returns false for other event sources defined in the referenced assemblies.

In WebEvents:
    [EventSource(Name = "WebEvents")]
    public class WebEventSource : EventSource
    {
        public static readonly WebEventSource Log = new WebEventSource();

        [Event(100, Level = EventLevel.Informational, Message = "Testing")]
        public void Test()
        {
            if (IsEnabled())
                WriteEvent(100);
        }
    }
A similar class is defined in the assembly that handles caching - the only difference being the name of the EventSource. When calling methods in the caching assembly, they try to log events to its local EventSource ("CachingEvents"). However, despite listening for it using SemanticLogging-svc.exe, the IsEnabled() calls return false.

Config file for SemanticLogging-svc:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw/SemanticLogging-svc.xsd">
  
  <eventSources>
    <eventSource name="WebEvents">
      <eventListeners>
        <eventListener name="console" level="Verbose" />
      </eventListeners>        
    </eventSource>
    <eventSource name="CachingEvents">
      <eventListeners>
        <eventListener name="console" level="Verbose" />
      </eventListeners>        
    </eventSource>
  </eventSources>
  <eventListeners>
    <consoleEventListener name="console" />
  </eventListeners>

</configuration>
The first line works, the second doesn't:
        WebEventSource.Log.Test();
        CachingEventsSource.Log.Test();
Any help would be much appreciated!
Sep 2, 2013 at 4:11 PM
It looks like you are using the preview release; you should upgrade to the final production release which you can get here: http://go.microsoft.com/fwlink/p/?LinkID=290903. Then the configuration would look something like this post: http://entlib.codeplex.com/discussions/446981#post1073948.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Sep 3, 2013 at 7:26 AM
Randy,

Thank you for pointing that out. Having downloaded the final release, and adjusting the configuration file accordingly, didn't solve the problem. Again, only the EventSource in the startup assembly works as intended. The referenced assembly that has its own EventSource, doesn't get its events picked up by the out-of-process listener.

However, I managed to figure it out. The following code doesn't work. Note that this method isn't even being called! Yet it causes the IsEnabled() call in another method to fail.
        [Event(100, Level = EventLevel.Verbose)]
        public void LocalCacheItemRead(string cacheItem, object key)
        {
            if (IsEnabled())
            {
                WriteEvent(100, cacheItem, key.ToString());
            }
        }
Changing the signature of the method, making the "key" parameter a string rather than an object, solves the problem. This may be stated in the docs somewhere, but I haven't seen it. Even if it's there, this fact should be emphasized. Is this a bug or by design? Which types besides string and int are acceptable?
Sep 3, 2013 at 8:37 AM
The issue is that object is not a valid parameter type for an EventSource Manifest. To verify the EventSource it is recommended to use the EventSourceAnalyzer:
EventSourceAnalyzer.InspectAll(WebEventSource.Log);

If you run the above with the LocalCacheItemRead method you will see the following exception: "System.ArgumentException: Unsupported type Object in event source."

The section "Checking an EventSource Class for Errors" in the help file lists the specific validations.

I don't think I've found a formal list of EventSource supported parameter types. However, the current allowable types are:
Boolean, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, String, Guid.
Another thing not to do is change the type (e.g. calling ToString()). From EventAttribute:
When you apply this attribute to an ETW event method defined on an EventSource-derived class, you must call the WriteEvent method on the base class, passing the event ID, followed by the same arguments as the defined method is passed.
Why doesn't my EventSource produce any events? goes into some of the details around what is going on. Basically, an error occurs and is swallowed and then the EventSource will not be enabled and WriteEvent calls will not do anything.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by randylevy on 10/7/2013 at 11:02 PM
Sep 3, 2013 at 8:55 AM
First class service Randy, thank you!
Dec 5, 2013 at 9:36 PM
Hi, I have a similar issue with a web application.

When AExpense sample application is running in IIS and sending events using MyEventSource, defined in a separate assembly, Semantic Logging cannot retrieve Keywords value. All works as expected when events are send from the console application and AExpense hosted in ASP.NET Development Server. Here is debug info from Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.TraceEventSchemaCache, GetSchema(TraceEvent traceEvent) method.

traceEvent
{<Event MSec= "11233.1290" PID="5720" PName= "" TID="4380" EventName="Initialize" ProviderName="MyEventSource" ErrorCode="" TrackingId="" ServiceId="" InstanceId="" Component="ExpenseRepository" Function="" LineNumber="" ServiceIpAddress="" Domain="" SystemId="" UserIpAddress="" UserId="" Action="" ActionData=""/>}
[Diagnostics.Tracing.Parsers.DynamicTraceEventData]: {<Event MSec= "11233.1290" PID="5720" PName=        "" TID="4380" EventName="Initialize" ProviderName="MyEventSource" ErrorCode="" TrackingId="" ServiceId="" InstanceId="" Component="ExpenseRepository" Function="" LineNumber="" ServiceIpAddress="" Domain="" SystemId="" UserIpAddress="" UserId="" Action="" ActionData=""/>}
ActivityID: {00000000-0000-0000-0000-000000000000}
Channel: Default
ClassicProvider: false
DataStart: 150544536
EventDataLength: 62
eventID: 250
eventIndex: 1
EventIndex: 1
EventName: "Initialize"
eventRecord: 0x0852ab50
EventTypeUserData: null
FixupETLData: null
FormattedMessage: null
ID: 250
Keyword: None
Level: Informational
lookupAsClassic: false
lookupAsWPP: false
myBuffer: 0
next: null
opcode: Info
Opcode: Info
OpcodeName: ""
opcodeName: ""
ParentThread: -1
PayloadNames: {string[14]}
payloadNames: {string[14]}
PointerSize: 8
ProcessID: 5720
ProcessName: ""
ProcessorNumber: 2
ProviderGuid: {8983a2e6-c5d2-5a1f-691f-db243cb1f681}
providerGuid: {8983a2e6-c5d2-5a1f-691f-db243cb1f681}
ProviderName: "MyEventSource"
providerName: "MyEventSource"
RelatedActivityID: {00000000-0000-0000-0000-000000000000}
Source: {Diagnostics.Tracing.ETWTraceEventSource}
source: {Diagnostics.Tracing.ETWTraceEventSource}
StringOnly: false
Task: 4
task: 4
taskGuid: {00000000-0000-0000-0000-000000000000}
TaskName: "Initialize"
taskName: "Initialize"
ThreadID: 4380
TimeStamp: {12/5/2013 2:21:35 PM}
TimeStamp100ns: 130307520951945745
TimeStampQPC: 39913348649
TimeStampRelativeMSec: 11233.129
userData: 150544536
Version: 1
schema
{Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Schema.EventSchema}
EventName: "Initialize"
Id: 250
id: 250
Keywords: None
keywords: None
KeywordsDescription: null
keywordsDescription: null
level: Informational
Level: Informational
opcode: Info
Opcode: Info
opcodeName: ""
OpcodeName: ""
Payload: {string[14]}
payload: {string[14]}
providerId: {8983a2e6-c5d2-5a1f-691f-db243cb1f681}
ProviderId: {8983a2e6-c5d2-5a1f-691f-db243cb1f681}
ProviderName: "MyEventSource"
providerName: "MyEventSource"
Task: 4
task: 4
taskName: "Initialize"
TaskName: "Initialize"
Version: 1
version: 1