TraceOutputOptions not honored

G

Guest

I would like my trace entries to have a timestamp so I figured I
could set the properties on the trace listener to accomplish this but THAT
that doesn't see to work .
dim txtListener as System.Diagnostics.TextWriterTraceListener = new
System.Diagnostics.TextWriterTraceListener(sw, "txt_listener")
txtListener.TraceOutputOptions = TraceOptions.DateTime


Log entries don't get any time info when written.

Doc says that these options aren't available for EventLogTraceListener but
there isn't anything restricting TextWriterTraceListener nor should there be
..



Any ideas ?
thanks
 
W

Walter Wang [MSFT]

Hi,

For the built-in TraceListener classes, EventLogTraceListener and
WebPageTraceListener will not use TraceOutputOptions to output additional
content. Following built-in TraceListener classes should honor
TraceOutputOptions correctly:

* DefaultTraceListener
* TextWriterTraceListner
* ConsoleTraceListener
* DelimitedListTraceListener
* XmlWriterTraceListener

However, these additional trace data controlled by TraceOutputOptions will
not be generated if you are directly calling Write() or WriteLine() method.
For these Write* methods, if will output only the message you let them
output, they will not add additional content such as DateTime.

You can use following code snippet to test it:

#Const TRACE = True
Dim txtListener As System.Diagnostics.TextWriterTraceListener = New
System.Diagnostics.TextWriterTraceListener(System.Console.Out,
"txt_listener")
txtListener.TraceOutputOptions = TraceOptions.DateTime
System.Diagnostics.Trace.Listeners.Add(txtListener)
System.Diagnostics.Trace.WriteLine("This message will not add
DateTime.")
System.Diagnostics.Trace.TraceError("This error message will add
DateTime.")

Since you're asking in ASP.NET newsgroup (and based on your previous post
about WebPageTraceListener), I assume you're use System.Diagnostics.Trace
from ASP.NET web application. As I mentioned above, WebPageTraceListner
will not use TraceOutputOptions to output additional content. However, I
think the output generated by ASP.NET TraceContext may have the date time
information you required:

Here's an explanation of the "Trace Information" section contents in the
asp.net trace log:

=========================
Category

A custom trace category that you specified as the first argument in a
trace.Write (or trace.Warn) method call.

Message

A custom trace message that you specified as the second argument in a
Trace.Write (or Trace.Warn) method call.

From First (s)

The time, in seconds, since the request processing was started (a running
total).

From Last (s)

The time, in seconds, since the last message was displayed. This column is
especially helpful for seeing how long individual operations are taking.
=========================

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

It wasn't clear or even mentioned in the documentation that the traceOptions
are only available when calling traceError,warn or info . Additionally ,
looking at the output I do get with Trace.TraceInfo with DateTime set, it is
not formatted as I would like.
... so it's nice to have all these features but they aren't very useable
so I suppose we will just write our own .

thanks anyway
 
W

Walter Wang [MSFT]

I understand your concerns about the documentation, please feel free to
give your feedback on the MSDN online documentation.

In the meanwhile, if you need help on how to create your own TraceListener,
please don't hesitate to let us know.

Thank you for using MSDN Managed Newsgroup service!


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top