Where is the stack trace logged?

Topics: Semantic Logging Application Block
Mar 6, 2013 at 7:27 PM
Edited Mar 6, 2013 at 7:28 PM
I was expecting the Semantic App block to automatically log the stack trace, so when it did not, I tried calling WriteEvent with an exception, such as:
WebAppEventSource.Log.Error(new Exception("test exception"));
[Event(3, Message = "An error has occured", Level = EventLevel.LogAlways)]
        internal void Error(Exception e)
This did not produce any additonal information in the Payload column or RawMessage column.

The Payload column is simply {} (empty).
Mar 7, 2013 at 4:59 AM
Edited May 1, 2013 at 9:38 PM
If I try to use the code above I get a runtime exception:
"Unsupported type Exception in event source."
This happens when trying to create the manifest. Only certain types are supported as arguments (basically primitive types plus a few others such as string, GUID).

I realize that you are probably just working through the block so perhaps the approach above is just for testing. That said, the approach of the Semantic Logging Application Block is a bit different than just logging a general error like with a traditional logger (such as log4net -- I use that as an example since it explicitly has a Logger.Error method). Typically, you would define an event and describe the specific structured information associated with that event.

So instead of WebAppEventSource.Log.Error(...) you might have something more like this:
The ShipOrderFailed event now has meaning -- when we (or potentially monitoring software for example) see the ShipOrderFailed event we know what has happened. And we also have a well defined (structured) set of information that is associated with that event (which can be used for reporting or other automated tasks). This is in contrast to the usual Logger.Error("Failed to ship order " + orderId); that you might see.

Also, if you only instantiate an exception but do not throw it then the StackTrace will be null. The stack trace is captured just before it is thrown.

Randy Levy
Enterprise Library support engineer
Support How-to
Mar 11, 2013 at 9:08 PM
Edited Mar 11, 2013 at 9:12 PM
Thanks for the explanation. My use case is a little bit more broad.

I am considering creating a single reusable "WebAppEventSource" for a set of .NET web apps spanning many developers. This would mean other developers could just use the WebAppEventSource on a new web app without any extra configuration steps for adding their own custom EventSource listener to SemanticLogging-svc.xml on our servers (Dev, Cons, Bench, Production).

This WebAppEventSource would have a broad set of methods used for tracing and error logging:
-LogPageStart, LogPageStop, LogDBQueryStart, LogDBQueryEnd, LogPageError, LogDBError, LogWSError, etc

I thought maybe I could have one listener for WebAppEventSource, and let developers inherit from it thus reusing the existing listener, but this doesn't work.
[EventSource(Name = "WebAppEventSource")]
    public class PhonebookEventSource : WebAppEventSource
        [Event(4, Message = "DB Query failed", Level = EventLevel.LogAlways)]
        internal void LogDBError(string message)
            WriteEvent(4, message);

        public static readonly PhonebookEventSource Log = new PhonebookEventSource();
On a side note, our current custom logging module automatically grabs the Application's Namespace and uses that to automatically create a new event log in Eventvwr for each new web application. I was thinking of doing the same thing with Semantic Logging block in order to have several web apps using the same event listener (the app's name space might be logged via: WriteEvent(4, message, appNameSpace).
Mar 12, 2013 at 6:46 AM
I don't think that inheritance is supported for EventSource as per Vance Morrison's response in the comments of his blog:
Finally as to your question on inheritance and EventSource: it is not supported. It is not clear what the expected meaning woudl be of inherited EventSources woudl be, but most interpretations have versioning problems.
Both the article and comments are worth reading.

Randy Levy
Enterprise Library support engineer
Support How-to