473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't trace write timestamp?

I have this in an app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.diagnos tics>
<trace autoflush="true " indentsize="2">
<listeners>
<add name="myListene r" traceOutputOpti ons="Timestamp"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\TestConsole \MyListener.log "/>
</listeners>
</trace>
</system.diagnost ics>
</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 23152
Brett Romero <ac*****@cygen. com> wrote:
I have this in an app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.diagnos tics>
<trace autoflush="true " indentsize="2">
<listeners>
<add name="myListene r" traceOutputOpti ons="Timestamp"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\TestConsole \MyListener.log "/>
</listeners>
</trace>
</system.diagnost ics>
</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.TraceErro r, Trace.TraceInfo rmation or Trace.TraceWarn ing
- not the Write* methods.

--
Jon Skeet - <sk***@pobox.co m>
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.TraceInfo rmation("");

and see this entry in the log file:
TestConsole.vsh ost.exe Information: 0 :
Timestamp=16209 13894489365

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.TraceInfo rmation("");

and see this entry in the log file:
TestConsole.vsh ost.exe Information: 0 :
Timestamp=16209 13894489365

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.co m>
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" ?>
<configuratio n>
<system.diagnos tics>

<trace autoflush="true " indentsize="2">
<listeners>
<add name="myListene r" traceOutputOpti ons="DateTime"
type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "C:\Test\bin\De bug\MyListener. log"/>
</listeners>
</trace>

</system.diagnost ics>
</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.WriteLi ne(). 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.Diagnost ics;

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

}

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

(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.WriteLi ne(). 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.co m>
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
7960
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 don't ask me why) indicating that there was something wrong with the requested operation. Assuming that I don't really know all the posible exceptions that might arise from the COM+ layer, and therefore I can't accurately return an int identifying...
8
1581
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 are called, some might be called multiple times, the order of functions called might be different each time. I would like to log all this, what function actually got called... this is my plan create a global string named TRACE
6
1730
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 file, Trace.axd. Does anyone know why? Thanks.
2
1829
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: ****************************************************************************** Compiler Error Message: CS0246: The type or namespace name 'trace' could not be found (are you missing a using directive or an assembly reference?) Source Error:
1
2960
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 that I could see the trace messages from the component. Here's what I've added to web.config so far: <system.web>
0
1343
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 the screen and writes to a text file). The problem happens any subsequent time the app. is used--tracing doesn't happen. It's as if tracing just turns itself off. So, we only get tracing on the first time the app runs but never any other time. ...
6
3959
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); objTraceListener = new TextWriterTraceListener(objStream); Trace.Listeners.Add(objTraceListener); So, now all Debug.Write and Trace.Write get logged to the file. In the d'tor I am doing:
3
3760
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 responsed in the remoting group after a week, so I'm throwing a little wider net this time. I have a desktop app (FFx 2.0) developed with Studio 05 that loads assemblies in a separate AppDomains from the primary UI. I'd like to be able to hook up...
20
5117
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 snip in question: $file = "time";
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.