C # Action XML if there is no direct append created existence

Source: Internet
Author: User

#region Write operations log----------------this format

<log operator = "Admin" Operation result = "Success" Result details = "Data export succeeded!" "Operating time =" 2014/5/2714:37 "/>


<summary>
Write operation Log
</summary>
<param name= "Loginfo" > What to write to the log </param>
<param name= "Flagofresult" > Success or Failure </param>
public static void Writelog (string loginfo, int flagofresult, string path)
{
Try
{
if (! System.IO.Directory.Exists ((path)))
System.IO.Directory.CreateDirectory (path);
String LogPath = path + "Log.xml";
XmlDocument doc = new XmlDocument ();
if (! File.exists (LogPath))
{
XmlNode node = doc. Createxmldeclaration ("1.0", "Utf-8", "" ");
Doc. AppendChild (node);
Creating the root node
XmlNode root1 = doc. CreateElement ("Logs");
XmlElement XE = Doc. CreateElement ("Log");
Xe. SetAttribute ("operator", "Admin");
Xe. SetAttribute ("Operation result", Flagofresult = = 1?) "Success": "Failure");
Xe. SetAttribute ("Result details", loginfo);
Xe. SetAttribute ("Operating Time", DateTime.Now.ToShortDateString () + DateTime.Now.ToShortTimeString ());
Root1. AppendChild (XE);
Doc. AppendChild (ROOT1);
Doc. Save (LogPath);
}
Else
{
Doc. Load (LogPath);
Find root node
XmlNode root = Doc. selectSingleNode ("Logs");

Create a Datainfos node
XmlElement XE = Doc. CreateElement ("Log");
Xe. SetAttribute ("operator", "Admin");
Xe. SetAttribute ("Operation result", Flagofresult = = 1?) "Success": "Failure");
Xe. SetAttribute ("Result details", loginfo);
Xe. SetAttribute ("Operating Time", DateTime.Now.ToShortDateString () + DateTime.Now.ToShortTimeString ());
Root. AppendChild (XE);
Doc. Save (LogPath);
}
}
catch (Exception)
{

Return
}

}


#endregion

C # Action XML if there is no direct append created existence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.