472,995 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,995 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 23001
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.