troubleshooting Question

Problem with LINQ XML logging

Avatar of techsuppoprt
techsuppoprt asked on
.NET ProgrammingC#
4 Comments1 Solution223 ViewsLast Modified:
Hello Experts

I'm using LINQ to XML I have a bit of a problem with writing to a XML file. It seems that instead of inserting XML nods the framework is writing to the XML file as a streamer, line by line.

I'm using a XML file to record my program events aka logging. If the program is closed before all  processes are finished the XML logging file ends up being unfinished.

Example:
Initial log file:

<root>
<processInfo>
<\processInfo>
 <events>
  <event>
 //Logging event info
  <\event>
 <\events>
<root>

I would expect, as the process runs, for the program to keep the tags and just keep on adding <event> nods with log entries ( and it works fine if I let it run ) but if the process is interrupted I end up with something like this:

<root>
<processInfo>
<\processInfo>
 <events>
  <event>
  This is my logging event info. It was cut off in the mid
 
How can I avoid this problem and make sure that even if my program process is interrupted the XML Logging file closing tags are still there ?

Thank you.
<root>
<processInfo>
<\processInfo>
 <events>
  <event>
 //Logging event info
  <\event>
 <\events>
<root>
<root>
<processInfo>
<\processInfo>
 <events>
  <event>
  This is my logging event info. It was cut off in the mid
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros