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

  • SEARCH
  • Home
  • 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 3403746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:17:54+00:00 2026-05-18T05:17:54+00:00

i am adding tracing for audit purposes of a simple process i have built

  • 0

i am adding tracing for audit purposes of a simple process i have built as an .exe and set in the scheduler to run every 10 minutes. i want to have the application output the results into an xml file.

if the file exists then open and append data to it, if it does not exist i want to create a new xml file that will be persisted and used on next run.

here is my code now, what do i need to add, how do i open the xml file (on c:/file.xml) and use it to append nodes to?

static void Main(string[] args)
{
    XmlDocument doc = new XmlDocument();

    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
    doc.AppendChild(dec);// Create the root element

    XmlElement root = doc.CreateElement("STATS");
    doc.AppendChild(root);

    XmlElement urlNode = doc.CreateElement("keepalive");
    urlNode.SetAttribute("runTime", DateTime.Now.ToString());

    try
    {
        WebProxy wp = new WebProxy("http://proxy.ml.com:8083/");
        WebClient w = new WebClient();
        w.Proxy = wp;

        if (w.DownloadString("http://wwww.example.com") != "")
            urlNode.SetAttribute("result", "UP");
        else
            urlNode.SetAttribute("result", "DOWN");
    }
    catch
    {
        urlNode.SetAttribute("result", "DOWN");
    }
    finally
    {
        root.AppendChild(urlNode);
        doc.Save("c:/keepAlive.xml");
    }
}
  • 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-18T05:17:55+00:00Added an answer on May 18, 2026 at 5:17 am

    You can’t append an XML file – you’ll have to load the file in memory , modify/add/etc, and then write it to disk.

    EDIT :

    Well, for loading a file you would use :

    XmlDocument xmlDoc= new XmlDocument(); // create an xml document object.
    if(System.IO.File.Exists("yourXMLFile.xml")
        xmlDoc.Load("yourXMLFile.xml");// load from file
    else{
       // create the structure of your xml document
       XmlElement root = xmlDoc.CreateElement("STATS");
       xmlDoc.AppendChild(root);
    }
    

    and then start adding the keepalive stuff.

    I would actually go a bit further and not mess around with xml. I’d create a class that contains everything I need and just serialize and deserialize it.

    Like this:

    [XmlRoot]
    public class Stats{
      public Stats(){}
      public IList<StatsItem> Items{get;set;} 
    }
    
    public class StatsItem{
      public StatsItem(){}     
    
      public string UrlName{get;set;}
      public DateTime Date{get;set;}
    }
    

    now just serialize this, and you have your xml document. When the time comes, deserialize it, add stuff to the Items list and serialize and save it to disk again.

    There are lots of resources on google , so just search a bit for those.

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

Sidebar

Related Questions

Adding an element to the head of an alist (Associative list) is simple enough:
I have all of my connections set up from my code, as opposed to
For a given class I would like to have tracing functionality i.e. I would
I have a couple of Github projects that I want to be able to
I am developing a GPS-based app and have just started adding in my UX
While adding text in a textarea, I dont want to allow '*' after '&'.
I have a loop adding fields to a manager, I am trying to delay
Can I have Eclipse adding my string resources as I code or do I
I was thinking of adding some Achievements to our internal bug-tracking and time logging
Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere_else/source.cpp, vs. just

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.