Topic: Filtering By Namespace/Stack without using ProcessFlow
Our organization already uses the .NET diagnostics framework to perform tracing this is somewhat limited in the scope of tracing that can be accomplished. I have found it difficult to get the executing method into the trace output and to allow it to be filtered. Support suggested that I use the session name as a method to do this. Below is a snippet of code I used incase anyone else may run into a similar issue:
//NOTE: We dont use eventCache.Callstack in any other configured TraceListener
//If eventCache.Callstack is called it will result in two stack traces can be an expensive
//operation
StackTrace stack = new StackTrace(SkipFrames, true);
using (DataViewerContext context = new DataViewerContext())
{
context.AppendLine("Message:");
context.AppendLine(message);
if (Callstack)
{
context.AppendLine(String.Empty);
context.AppendLine("Callstack:");
context.AppendLine(stack.ToString());
}
LogEntry entry = new LogEntry();
entry.ViewerId = context.ViewerId;
entry.ProcessId = eventCache.ProcessId;
entry.ThreadId = Int32.Parse(eventCache.ThreadId, NumberStyles.HexNumber);
entry.Timestamp = Session.Parent.Now();
entry.Color = Session.Color;
entry.Level = level;
entry.LogEntryType = TranslateEntryType(eventType);
//Replace session name with stack frame method DeclaringType or prefix with CustomAttribute
if(stack.FrameCount > 0) entry.SessionName = stack.GetFrame(0).GetMethod().DeclaringType.FullName;
if (!String.IsNullOrEmpty(Session.Name)) entry.SessionName = String.Concat('[',Session.Name, ']', entry.SessionName);
entry.Title = message;
entry.Data = context.ViewerData;
Session.Parent.SendLogEntry(entry);
}Last edited by abstractlabs (2010-02-09 01:04:01)
