How to create well-formed XML with WCF messages

Topics: Building and extending application blocks, Logging Application Block, Validation Application Block
Jan 21, 2010 at 12:10 AM

I am able to integrate WCF app to log messages using EntLibLoggingProxyTraceListener. It populates messages with relevant tags
(xml elements and attributes) but the root element is missing.  That is why when reading that file by XmlTextReader it's giving problem because of missing root element.

Can you pls tell me how can I add root elements without modifying that file.

Jan 21, 2010 at 3:38 AM

The easiest way I could think is to use the flat file tracelistener instead of the xml trace listener.  Add a TextFormatter and sort of convert it to an XmlFormatter by modifying the Template property. For example, this is how the TextFormatter looks like:

Timestamp: {timestamp}
Message: {message}
Category: {category}

Modify it so that each value you want to display is wrapped in an xml element and enclose it in a LogEntry element or anything you like:

<LogEntry>
     <Timestamp>{timestamp}</Message>
     <Message>{message}</Timestamp>
</LogEntry>

Assign this as your flat file trace listener's Formatter and don't forget to remove the headers and footers.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 21, 2010 at 5:31 AM

Many thanks for your prompt reply.

Nesar

From: AvanadeSupport [mailto:notifications@codeplex.com]
Sent: Thursday, 21 January 2010 2:38 PM
To: Nesar Bhuiyan
Subject: Re: How to create well-formed XML with WCF messages [entlib:81504]

From: AvanadeSupport

The easiest way I could think is to use the flat file tracelistener instead of the xml trace listener. Add a TextFormatter and sort of convert it to an XmlFormatter by modifying the Template property. For example, this is how the TextFormatter looks like:

Timestamp: {timestamp}
Message: {message}
Category: {category}

Modify it so that each value you want to display is wrapped in an xml element and enclose it in a LogEntry element or anything you like:

<LogEntry>
<Timestamp>{timestamp}</Message>
<Message>{message}</Timestamp>
</LogEntry>

Assign this as your flat file trace listener's Formatter and don't forget to remove the headers and footers.

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Read the full discussion online.

To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)

To start a new discussion for this project, email entlib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Please consider the environment before printing this e-mail.

The information contained in this email and any attachment is confidential and may contain legally privileged or copyright material. It is intended only for the use of the addressee(s). If you are not the intended recipient of this email, you are not permitted to disseminate, distribute or copy this email or any attachments. If you have received this message in error, please notify the sender immediately and delete this email from your system. The ABC does not represent or warrant that this transmission is secure or virus free. Before opening any attachment you should check for viruses. The ABC's liability is limited to resupplying any email and attachments.
Jan 21, 2010 at 6:05 AM

You can also try the Custom Trace Listener (see http://msdn.microsoft.com/en-us/library/cc309289.aspx) and use the XML related classes to produce the XML file from your log (http://msdn.microsoft.com/en-us/library/4d1k42hb(VS.71).aspx

Benjie
Avanade Support
b.p.fallar@avanade.com