Semantic Logging does not log the updated event source message in Out-Of-Process

Topics: Semantic Logging Application Block
Oct 30, 2014 at 4:03 PM
Edited Oct 30, 2014 at 4:05 PM
I am using Semantic Logging Out-Of-Process in my application. I have created an eventsource class as shown below

[EventSource(Name = "SemanticLoggingOutOfProcessEventSource")]
public class SampleEventSource : EventSource
{
public class Keywords
{
    public const EventKeywords Page = (EventKeywords)1;
    public const EventKeywords DataBase = (EventKeywords)2;
    public const EventKeywords Diagnostic = (EventKeywords)4;
    public const EventKeywords Perf = (EventKeywords)8;
}

public class Opcodes
{
    public const EventOpcode Start = (EventOpcode)20;
    public const EventOpcode Finish = (EventOpcode)21;
    public const EventOpcode Error = (EventOpcode)22;
    public const EventOpcode Starting = (EventOpcode)23;

    public const EventOpcode QueryStart = (EventOpcode)24;
    public const EventOpcode QueryFinish = (EventOpcode)25;
    public const EventOpcode QueryNoResults = (EventOpcode)26;

    public const EventOpcode CacheQuery = (EventOpcode)27;
    public const EventOpcode CacheUpdate = (EventOpcode)28;
    public const EventOpcode CacheHit = (EventOpcode)29;
    public const EventOpcode CacheMiss = (EventOpcode)30;
}

public class Tasks
{
    public const EventTask Page = (EventTask)1;
    public const EventTask DBQuery = (EventTask)2;
    public const EventTask Application = (EventTask)3;            
}

[Event(1, Message = "Method1 Starting.", Opcode = Opcodes.Starting, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method1Starting() { if (this.IsEnabled()) this.WriteEvent(1); }

[Event(2, Message = "Method1 Ending.", Opcode = Opcodes.Finish, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method1Ending() { if (this.IsEnabled()) this.WriteEvent(2); }

[Event(3, Message = "Method2 Starting.", Opcode = Opcodes.Starting, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method2Starting() { if (this.IsEnabled()) this.WriteEvent(3); }

[Event(4, Message = "Method2 Ending.", Opcode = Opcodes.Finish, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method2Ending() { if (this.IsEnabled()) this.WriteEvent(4); }

public static readonly SampleEventSource outOfProcessLog = new SampleEventSource();               
}

I set the eventsource name in the packages\EnterpriseLibrary.SemanticLogging.Service.2.0.1406.1\tools\SemanticLogging-svc.xml. I started the Semantic Service and ran the application. The log was written to the "packages\EnterpriseLibrary.SemanticLogging.Service.2.0.1406.1\tools\SemanticLogging-svc.runtime.log" file. I have the following issues:
  1. Whenever i make a change to the Message attribute ( suppose i change the "Method1 Starting." to "Method1 Started."). The log is written again as "Method1 Starting." instead of "Method1 Started.". Why? The only way i could achieve this is to stop the service and change the EventSource Name everytime there is an update to Message attribute, which is very painful. Is there any other way to achieve this without changing the EventSource name?
  2. Is it possible to log messages to any other log file instead of logging to SemanticLogging-svc.runtime.log?
  3. I could only create EventOpcode starting from 20. Wont i be able to start EventOpcodes from 1 similar to Tasks?
Please provide me the information asap which will help me achieve the output.
Oct 30, 2014 at 5:22 PM
Item #1 sounds like a schema caching issue similar to this work item. The two workarounds posted on that work item are to delete the cahced provider info or to run the OOP service in console mode. Also, typically and

Is it possible to log messages to any other log file instead of logging to SemanticLogging-svc.runtime.log?

You can modify the SemanticLogging-svc.xml file (which is the default config file used by the OOP service) to write direct the events to another file (or another sink).

I could only create EventOpcode starting from 20. Wont i be able to start EventOpcodes from 1 similar to Tasks?

You should be able to create an Opcode with a lower value than 20. However, there are some reserved Opcodes. From the Developer's Guide:

If you choose to define custom opcodes, you should assign integer values of 11 or above, otherwise they will clash with the opcodes defined in the EventOpcode enumeration. If you define a custom opcode with a value of 10 or below, messages that use these opcodes will not be delivered.

If you try to use an Opcode of 10 or less you will receive an ArgumentException, "Opcode values less than 11 are reserved for system use". You can start using Opcodes at 11 and higher. Also, there is a built-in Opcode, Receive, with a value of 240; you can use it but the Opcode may display as Receive.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to