Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:42:32+00:00 2026-05-24T12:42:32+00:00

I am dumping some log events into an XML file, every 5 minutes I

  • 0

I am dumping some log events into an XML file, every 5 minutes I start a new file. I’ve been using XDocument and XElement which I really like,

 _xDocument = XDocument.Parse("<LogEntires/>");
 _xDocument.Root.Add(xElementLogEventList.ToArray());
 _xDocument.Save(_outFileName);

I’d like to persist it to disk every 10 seconds or so with a timer so the most recent events are not just in memory, and people can examine the file if necessary. But XDocument only has Save() and WriteTo() methods which write the whole document. And guess without the < /Root > tag it would be invalid Xml anyway.

My next thought is to use XmlWriter and flush my FileStream now and then, keeping track of adding the closing < /Root > tag myself… and just have invalid XML until I’m completely done and close the file.

I’d really like to have valid Xml on the disk and If I wanted to write a root tag and then five or ten seconds later when I make my next flush, just backup and remove the root tag, append the next hundred elements and write and flush the stream. xmlWriter is forward only so I’m not sure the most efficient way to do this.

What is the most efficient way to have valid xml on disk, but keep streaming new elements in at the end, and not re-write the whole document every time? My fear is that I’m missing something obvious like a xDocument.AppendUpdatesToFile(_outfile) or something obvious like that…

If not how would you efficiently find and remove the final root tag and append the new elements in a streaming manner?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:42:33+00:00Added an answer on May 24, 2026 at 12:42 pm

    XML is not friendly to this kind of updates on disk.

    Consider using collection of XML fragments (essentially omiting initial openeing tag) if you have to stick with XML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm trying to get some XML into an easy format for dumping into
Simple usecase : assemble an Eclipse product using simple scripts, just dumping bundles into
I am dumping a cvs file into a datatable. I am able to loop
I am dumping \t delimited data using using OutputDebugString and then use ex-Sysinternals DebugView
How can I specify the filename when dumping data into the response stream? Right
I'm using hibernate 3 and want to stop it from dumping all the startup
I often use print_r($value, true) to dump some variables in log statements, and sometimes
I have a table where I am dumping some transaction data. I have a
I have fetched some 1000 records using data adaptor and displayed in the UI(DataGrid).
I've got some csv-files that I need to import to our system using php.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.