473,394 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why doesn't trace write timestamp?

I have this in an app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener" traceOutputOptions="Timestamp"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\TestConsole\MyListener.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

The code I'm using to write is this:

Debug.WriteLine("Hello config file.");

I just want to output variable values but also would like a time stamp
appended with every .Write or .WriteLine. First, what is the above
timestamp option doing (this came from intellisense) and how do I get
the behavior I'm looking for?

Thanks,
Brett

Apr 10 '06 #1
5 23097
Brett Romero <ac*****@cygen.com> wrote:
I have this in an app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener" traceOutputOptions="Timestamp"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\TestConsole\MyListener.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

The code I'm using to write is this:

Debug.WriteLine("Hello config file.");

I just want to output variable values but also would like a time stamp
appended with every .Write or .WriteLine. First, what is the above
timestamp option doing (this came from intellisense) and how do I get
the behavior I'm looking for?


Having had a little experiment, it looks like this is only used when
you call Trace.TraceError, Trace.TraceInformation or Trace.TraceWarning
- not the Write* methods.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 10 '06 #2
I see: I'm using:

Trace.Flush();
Trace.TraceInformation("");

and see this entry in the log file:
TestConsole.vshost.exe Information: 0 :
Timestamp=1620913894489365

How exactly can the readable date/time be written into the log?

Also, flush() doesn't seem to be doing anything. I still have all of
the previous log entries there. How can I clean out the log file on
each debug session or is this something I have to do completely
manually (streamwriter)?

Thanks,
Brett

Apr 10 '06 #3
Brett Romero <ac*****@cygen.com> wrote:
I see: I'm using:

Trace.Flush();
Trace.TraceInformation("");

and see this entry in the log file:
TestConsole.vshost.exe Information: 0 :
Timestamp=1620913894489365

How exactly can the readable date/time be written into the log?
Have you tried DateTime as an option instead of Timestamp?
Also, flush() doesn't seem to be doing anything. I still have all of
the previous log entries there. How can I clean out the log file on
each debug session or is this something I have to do completely
manually (streamwriter)?


Flush doesn't do what you think it does - it makes sure that any cached
data is flushed to disk.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 10 '06 #4
I tried datetime but that didn't do anything. Nothing is outputting in
that regard:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>

<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener" traceOutputOptions="DateTime"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Test\bin\Debug\MyListener.log"/>
</listeners>
</trace>

</system.diagnostics>
</configuration>

Any other suggestions on the timestamp?

I'd also like to output only certain code. It seems to be outputting
all errors. In other words, how do I configure a Trace in the
app.config file then reference it in code the same way I do Debug? For
example, the trace may be named myTrace and I can do
myTrace.WriteLine(). The log file will contain only entries that I
explicitly reference via myTrace.

Thanks,
Brett

Apr 10 '06 #5
Brett Romero <ac*****@cygen.com> wrote:
I tried datetime but that didn't do anything. Nothing is outputting in
that regard:
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Here's some sample code which uses the same configuration as yours:

using System;
using System.Diagnostics;

class Test
{
static void Main()
{
Trace.TraceInformation("Hello");
Trace.Flush();
}

}

Here's the result:
test Information: 0 : Hello
DateTime=2006-04-10T18:23:25.3437500Z

(Of course, you need to compile with TRACE defined.)
I'd also like to output only certain code. It seems to be outputting
all errors. In other words, how do I configure a Trace in the
app.config file then reference it in code the same way I do Debug? For
example, the trace may be named myTrace and I can do
myTrace.WriteLine(). The log file will contain only entries that I
explicitly reference via myTrace.


You can use Trace.Listeners["myTrace"] to get a specific TraceListener,
but I don't think you would normally do that. (TraceListener doesn't
seem to encourage you to use it directly.)

Perhaps you should look at other logging frameworks, such as Log4Net?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Angelos Karantzalis | last post by:
Hi y'all, recently I've come across a situation where a web service needs to deal with an exception that might arise, originating from a COM+ component. It then returns an int value (please...
8
by: Aaron | last post by:
this is what I want to do. i have an input box and a submit button. the input gets processed by my program and it returns the results. depending on the input, not all the functions in my program...
6
by: Joe Rattz | last post by:
I can get the Trace.Write() to work if I put the code in an aspx.cs file. But, I have a (C#) class called by my aspx.cs code that also has Trace messages, but none of them show up in the Trace...
2
by: tshad | last post by:
I have been working in VB.net and have never had a problem with trace.warn or trace.write. I have a test program in C# that is giving me an error: ...
1
by: Oleg Ogurok | last post by:
Hi there, My ASP.NET 2.0 app uses an external assembly that calls methods like Trace.Write() and Trace.TraceError() of namespace System.Diagnostics. I need to enable tracing in my web app so...
0
by: rehto | last post by:
We have an ASP.NET 2.0 (C#) app and we want to enable tracing (see the code snippets below). The first time a user navigates to the app., the tracing works fine (the ASP.NET tracing appears on...
6
by: Zytan | last post by:
According to http://www.15seconds.com/issue/020910.htm I am doing this in the c'tor of a 'logfile' class: objStream = new System.IO.FileStream(logFilename, System.IO.FileMode.OpenOrCreate);...
3
by: | last post by:
If this is simple, forgive my ignorance, but I'm coming from the CompactFramework where we don't use AppDomains. I did a fair bit of archive searching and couldn't find an answer and I got no...
20
by: cscorley | last post by:
For some reason, I cannot use fopen() on the file in write mode. The file "time" is in the same directory as the .php file, with permissions set to 0766. PHP Version 5.2.5 Apache/2.2.8 code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.