I'm having the darndest problem and I can't seem to recreate it anywhere, and
I'm looking for someone with a little insight.
I've created a custom EmailTraceListe ner which implements the TraceListener
abstract class. The EmailTraceListe ner stores all of the messages in a
StringBuilder internally and then writes the StringBuilder.T oString() to an
email as a text message.
Here's the problem I'm encountering. I load up several TraceListeners into
the Trace.Listeners property as a TraceListener[] and then write some
initialization information out to Trace.WriteLine calls, and then I go on my
way and do the normal Tracing. Then I send the email. What I'm seeing is
that the first few line breaks do not appear in my email. Everything is all
on one line. There are four initialization statements that are inserted
using Trace.WriteLine s at the beginning, and only the fourth statement is on
its own line. Weird, huh?
What's even weirder is if I try it with just a StringBuilder and the
System.Net.Emai l classes, I can't recreate it. I can't recreate it with a
TextWriterTrace Listener and a StringBuilder and the Email classes either.
Does anyone have any thoughts about why the first few line breaks would be
dropping off?
Thanks very much,
TheManFromSql 7 1905
Hi TheManFromSql,
From your description, you've written a custom TraceListener which will
write content into a email message's body and send it through the .NET
System.Net.Smtp components. However, you find the format of the email
message has some problem, correct?
As for the custom TraceWriter, would you provide some detailed code logic
about the write message methods? Also, as you mentioned that if you
directly create a StringBuilder and a the SMTP classes to write out the
same text data, they can be displayed well with new lines. If so, are you
using the identical code as the one in custom tracelistener? You can also
save them to a text file to verify the formatting. If you can save the
same text into a file with correct formatting, but failed through email
body, the problem is likely due to the email's body formatting. Also,have
you made sure the email body is of plain text format rather than html?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Steven,
Here is the implementation of the two required TraceListener methods (NOTE:
_emailContent is a StringBuilder object).
#region TraceListener required implementation
public override void Write(string message)
{
lock (this._emailCon tent)
{
this._emailCont ent.Append(mess age);
}
}
public override void WriteLine(strin g message)
{
lock (this._emailCon tent)
{
this._emailCont ent.AppendLine( message);
}
}
#endregion
That's it. For sending the email, I have a lightweight container class that
stores the StringBuilder.T oString() output as the body of the email. This
body then gets passed to the MailMessage class.
In debugging, I have stepped through the communication between the
EmailTraceListe ner and the MailMessage, and when I inspect the Body, I see
the \r\n's as part of the string. The only problem seems to be that the
first few are dropping off.
Thanks very much,
TheManFromSql
"Steven Cheng[MSFT]" wrote:
Hi TheManFromSql,
From your description, you've written a custom TraceListener which will
write content into a email message's body and send it through the .NET
System.Net.Smtp components. However, you find the format of the email
message has some problem, correct?
As for the custom TraceWriter, would you provide some detailed code logic
about the write message methods? Also, as you mentioned that if you
directly create a StringBuilder and a the SMTP classes to write out the
same text data, they can be displayed well with new lines. If so, are you
using the identical code as the one in custom tracelistener? You can also
save them to a text file to verify the formatting. If you can save the
same text into a file with correct formatting, but failed through email
body, the problem is likely due to the email's body formatting. Also,have
you made sure the email body is of plain text format rather than html?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for your reply,
Since you've ensured that the "\r\n" linefeed are part of the string during
debugging, I think the mail message should also contain the characters. Is
your email format set to html? If so, I suggest you try using "<br/>"
instead of "\r\n" to create new line since HTML does not recognize "\r\n"
as line feed, but use "<br/>" for insert new line.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
The email format is not set to HTML. It is only the first two or three lines
where line breaks are not being used. \r\n line breaks are working further
on in the email.
Thanks for your reply Themanfromsql,
Would you create a simplified project and send it to me? You can reach me
at the email in my signature (by remove "online").
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Themanfromsql,
Thanks for your mail, I've received your attachment of test project and
will have a look and test. I'll update you soon.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Themanfromsql,
I have performed some tests with the sample project you sent and here are
what I got in the local test:
I can correctly write out the trace statements and received the email(in
plain text format) and the email body is as below:
=============== =====
TraceListenerMa nager instance started listening at 05-28-2007
04:48:54.03202 Created by: TraceListenersT est, Version=1.0.0.0 ,
Culture=neutral , PublicKeyToken= null Connection String: Connection string
goes here.
Machine: GTSC-SC-LTBOX
TWO roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;
Then took the other, as just as fair,
And having perhaps the better claim
Because it was grassy and wanted wear;
Though as for that, the passing there
Had worn them really about the same,
And both that morning equally lay
In leaves no step had trodden black.
Oh, I marked the first for another day!
Yet knowing how way leads on to way
I doubted if I should ever come back.
I shall be telling this with a sigh
Somewhere ages and ages hence:
Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference.
TraceListenerMa nager instance stopped listening at 05-28-2007
04:48:54.03202 Elapsed time: 00:00:00
=============== ==========
It seems all the "Trace.WriteLin e" statement are correctly output in a new
line in the email body. Is this also what you get or should the expected
behavior different?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Daylor |
last post by:
hi.
i have application with 5 threads.
can i use the trace and tracelistener, so if i trace in thread1 , it will
write to
file1, and if i trace to thread2 if will write to file2.
hope im clear, have a nice day.
|
by: Schorschi |
last post by:
Anyone create a custom tracelistener that redirects to a database?
Or event to a memory stream rather than a file stream?
If an example of a memory stream, when the Write or WriteLine methods
get called I could redirect/parse the text to a database?
Not sure of the best way to do this, any suggestions welcome.
|
by: Jeff |
last post by:
Hello everybody,
I was doing one of the exercises in the K&R book, and I got something
really strange. Here's the source code:
/*
* Exercise 2-2 from the K&R book, page 42
*/
#include <stdio.h>
|
by: John Batdorf |
last post by:
Ugh. I obviously don't understand the correct way to use this thing!
I have several #if(DEBUG) code blocks to write to a file ErrorLog.txt
to troubleshoot why and what exceptions are being encountered.
So in my class this is defined:
static FileStream traceLog = new FileStream("ErrorLog.txt",
FileMode.OpenOrCreate, FileAccess.Write);
static TextWriterTraceListener traceListener = new
|
by: Mullin Yu |
last post by:
i have a problem with TraceListener. when i close the FileStream, i will
have the error:
"Cannot access a closed file"
but, if i remarks the statement => no closing the FileStream, i will have
another error:
"The process cannot access the file "C:\MyAppsTraceLog.log" because it is
being used by another process."
Remind that it's ok when i click the button once. the problem arises when
| |
by: fd123456 |
last post by:
Hi Kevin,
You were indeed right. Unfortunately, the ViewState property doesn't
change that behaviour. In case it can help someone else, here's the
trick I ended up doing. Supposing the variable to be bound to the
TextBox is called "s", and the TextBox itself is called "myTextBox",
the binding is as follows (c#):
myTextBox.Text = (s.StartsWith(Environment.NewLine) ?
Environment.NewLine : "") + s;
|
by: runningdog |
last post by:
Hi,
I would like to be able to embed a newline in a text string.
Is there any convienent notation to do this
TIA Steve
|
by: bonk |
last post by:
I have an application that initializes a lot of tracesources at
runtime. The names of these tracesources are only known at runtime. How
can I add one tracelistener to all tracesources using the config file
(since I do not own the sourcecode for some of the assemblies that
generate these tracelisteners)? If that is not possible, how can I
collect all tracemessages into one file? I am using .net framework 2.0.
|
by: =?Utf-8?B?YXJjaHVsZXRhMzc=?= |
last post by:
I want to send trace messages to a textbox in my winforms application using
C# 2.0. I have a custom TraceListener class (see below) that is very basic,
but I'v got an error implementing it that I don't understand. To instantiate
my class I have:
TextboxTraceListener TextBoxTracer = new TextboxTraceListener(txtLog);
Visual Studio underlines txtLog in blue and says:
"Error 2 A field initializer cannot reference the nonstatic field,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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: 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: 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();...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |