I would like to start using EventLogTraceLi stener, and am running into
a couple of significant limitations:
1) I have found that there is no way to write EventLog entries with
different EventLogEntryTy pes. It seems that EventLogTraceLi stener is
only capable of writing entries with EventLogEventTy pe.Informat*ion ,
even for Trace.Fail. Is this assessment correct?
2) EventLogTraceLi stener.Flush (and the idea of buffering writes) is
not applicable to EventLogTraceLi stener. It seems that each call to
Trace.Write() or Trace.WriteLine () results in the creation of a new
EventLog entry.
This behavior is undesirable and incompatible with my usage of
Trace.Write() and Trace.WriteLine (). For example:
try
{
// Remove the DefaultTraceLis tener
Trace.Listeners .Clear();
// Create EventLogTraceLi stener with an EventSource of "Test"
EventLogTraceLi stener evListener = new EventLogTraceLi stener("Test");
// Register the listener
Trace.Listeners .Add(evListener );
// Raise an exception
throw new Exception("Fake exception");
}
catch(Exception ex)
{
// Construct trace output message with date and exception info
Trace.Write(Sys tem.DateTime.No *w.ToString());
Trace.Write(ex. GetType().Name) *;
Trace.Write(ex. Message);
Trace.Write("\r \n");
Trace.WriteLine (ex.StackTrace) *;
}
The code above uses Write() and WriteLine() in the way that I believe
they were intended, based on the presence of other formatting methods
for intentation. This use of Trace works great for file logging.
If I add the EventLogTraceLi stener, however, the above code
will create five entries in the EventViewer, no matter how I use
Trace.AutoFlush and Trace.Flush(). This means that
EventLogTraceLi stener is essentially unusable for me if I have
widespread usage of Trace like that above.
Subclassing TraceListener to create a listener that writes "correctly"
to the EventViewer is not a viable option because the Trace class has
no members that would help to group a series of Write()/WriteLine()
calls into a a single logical log entry.
So ultimately, it is not possible to use Trace's
Write()/WriteLine()/buffering capabilities (standard for logging to
files and console) AND create meaningful EventViewer entries. This
seems like an oversight in the design of the Trace API.
Please comment; I would gladly be proven wrong on either point,
especially #2.
Ken 2 2375
Tracing works fine for both cases, but you have to remember that each write
operation is a single entry , where ever this entry goes, file or eventlog.
For event log if you want a single entry, simply build your complete string
message before wrtiting it. This is the way I use it
Don't forget also that EventLogTraceLi sner send EvenLog object.
You coudl you also directly the EventLog class
HOpe it helps
"Ken" wrote: I would like to start using EventLogTraceLi stener, and am running into a couple of significant limitations:
1) I have found that there is no way to write EventLog entries with different EventLogEntryTy pes. It seems that EventLogTraceLi stener is only capable of writing entries with EventLogEventTy pe.InformatÂ*io n, even for Trace.Fail. Is this assessment correct?
2) EventLogTraceLi stener.Flush (and the idea of buffering writes) is not applicable to EventLogTraceLi stener. It seems that each call to Trace.Write() or Trace.WriteLine () results in the creation of a new EventLog entry.
This behavior is undesirable and incompatible with my usage of Trace.Write() and Trace.WriteLine (). For example:
try { // Remove the DefaultTraceLis tener Trace.Listeners .Clear();
// Create EventLogTraceLi stener with an EventSource of "Test" EventLogTraceLi stener evListener = new EventLogTraceLi stener("Test");
// Register the listener Trace.Listeners .Add(evListener );
// Raise an exception throw new Exception("Fake exception"); } catch(Exception ex) { // Construct trace output message with date and exception info Trace.Write(Sys tem.DateTime.No Â*w.ToString()) ; Trace.Write(ex. GetType().Name) Â*; Trace.Write(ex. Message); Trace.Write("\r \n"); Trace.WriteLine (ex.StackTrace) Â*; }
The code above uses Write() and WriteLine() in the way that I believe they were intended, based on the presence of other formatting methods for intentation. This use of Trace works great for file logging.
If I add the EventLogTraceLi stener, however, the above code will create five entries in the EventViewer, no matter how I use Trace.AutoFlush and Trace.Flush(). This means that EventLogTraceLi stener is essentially unusable for me if I have widespread usage of Trace like that above.
Subclassing TraceListener to create a listener that writes "correctly" to the EventViewer is not a viable option because the Trace class has no members that would help to group a series of Write()/WriteLine() calls into a a single logical log entry.
So ultimately, it is not possible to use Trace's Write()/WriteLine()/buffering capabilities (standard for logging to files and console) AND create meaningful EventViewer entries. This seems like an oversight in the design of the Trace API.
Please comment; I would gladly be proven wrong on either point, especially #2.
Ken
Serge,
I understand what you're saying and agree that constructing the full
trace message prior to calling Trace.WriteLine () will get me what I
want.
I would submit, however, that the Trace's interface suggest an intended
usage much like a StreamWriter. This allows you to conveniently write
Trace information out to whatever persistence store you want. This
makes perfect sense for logging to a file or console (which is what
most of the examples illustrate), but it doesn't work so well with
stores that have a concept of a "record" like the eventlog or a
database. A critically important feature of Trace is that you can
dynamically determine who the listeners are, and Trace never needs to
care about who the listeners are. If you have to use Trace differently
depending on who is listening, you're taking away this key feature.
Ken This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stan |
last post by:
According to MSDN the following config files settings provide send tracing
information to event log:
<add name="MyListener"
<add name="MyEventListener"
type="System.Diagnostics.EventLogTraceListener, Version,
Culture, PublicKeyToken"
initializeData="MyConfigEventLog"/>
This doesn't work though.
|
by: Paulo Morgado |
last post by:
Hi al
How do I specify the EventLogEntryType when writing to
EventLogTraceListener
--
Paulo Morgad
Portuga
|
by: Brian Stubblefield |
last post by:
Dear clc members,
I am rather new to the C programming language.
I have a rather large program that I am currently debugging.
Currently, the following snippet of code in the c program:
char skillkey;
char (*fillkey_ptr)= skillkey;
|
by: Joerg Schoen |
last post by:
Hi folks!
"JSCPP" is a ANSI-C preprocessor and language parser. It can analyze or
instrument C-code. The most prominent application currently is to add
function trace calls to existing C programs simply by recompiling it.
The tracing will show when functions are entered or left along with the
arguments. Default is to trace EVERY function, but fine-grained control is
possible through a custom header file.
|
by: Bruno Jouhier [MVP] |
last post by:
I'm currently experiencing a strange phenomenon:
At my Office, Visual Studio takes a very long time to compile our solution
(more than 1 minute for the first project).
At home, Visual Studio compiles the same solution much faster (about 10
seconds for the first project).
My home computer is only marginally faster than the one I have at the office
(P4 2.53 vs. P4 2.4, same amount of RAM).
On the slow machine, the CPU usage is very low,...
| |
by: julien |
last post by:
Hi,
I have the following listeners in the web.config:
<add name="FileTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="D:\CapriMon\CapriMon.log"/>
<add name="EventLogTraceListener"
type="System.Diagnostics.EventLogTraceListener"
initializeData="CapriMon"/>
In my codebehind, I use Trace.WriteLine(...) whenever I want to log
|
by: Ken |
last post by:
I would like to start using EventLogTraceListener, and am running into
a couple of significant limitations:
1) I have found that there is no way to write EventLog entries with
different EventLogEntryTypes. It seems that EventLogTraceListener is
only capable of writing entries with EventLogEventType.Information,
even for Trace.Fail. Is this assessment correct?
2) EventLogTraceListener.Flush (and the idea of buffering writes) is
not...
|
by: duduch_1er |
last post by:
Hello i tried this code in my stylesheet :
xsl:variable name="items"
select="xsl-usexsl:getElementsBySplitString(.,'i')" />
whith the java function getElementsBySplitString
here the code :
public static Element getElementsBySplitString(String aToSplit, String
aSeparator) throws UseXslException {
|
by: srikar |
last post by:
Hi all,
I am having a problem, when I am compiling the code in 32 bit option on a
64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from
the linker .
/`../bin/amd64_stat_gnu_02015/WriteFault.o' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386 architecture of input file `../bin/amd64_stat_gnu_02015/WriteLogic.o' is incompatible with i386:x86-64 output
/usr/bin/ld: warning: i386...
|
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |