Question

I am using Enterprise Library 6 to implement logging, and user Tracing on an ASP.NET MVC 4 web application. I am using Tracers to achieve this, and I am writing LogEntries into a database. This works fine, but now, I want to add some extra info to the Tracer entries, into the ExtendedProperties field. I can do it on normal LogEntry objects, but I can't seem to do it on a Tracer. Is there any way to achieve this?

Here is what I'm doing:

using(traceManager.StartTrace(LogCategory.UserTracing.ToString(), activityId))
{
Doit();
}

Even if I assign the Tracer to a variable, I can't have any effect on the log entries it is writing. I have checked the TraceManager class too, but it also doesn't have anything to do with this.

What I would like to achieve is something like the following:

LogEntry e = new LogEntry();
e.ExtendedProperties.Add("key", "value");

Thanks in advance,

Robert

Was it helpful?

Solution

The Tracer class does not expose the LogEntry that is created so there is no way to achieve what you want out of the box.

Probably the easiest way to add extended property support is to get the source code for Tracer and create your own custom implementation that accepts extended properties. You could also create a custom TraceManager that uses the custom Tracer.

Also note that the out of the box FormattedDatabaseTraceListener does not log extended properties so you would need to create a custom trace listener to do that (you can find one approach at Enterprise Library Sample Projects).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top