奇妙なことに、ASP.Net プロジェクト (C# モードを使用) で結果をD:\Web.log
ファイルに記録できず、例外もスローされませんでした。
私の単純なコードに何か問題がありますか?
private static XmlDocument _doc = new XmlDocument();
private static string LogFileName = "D:\\Web.log";
static void LogToFile(string WebAddress, string IPAddress, string Title)
{
if (File.Exists(@"" + LogFileName + ""))
_doc.Load(@"" + LogFileName + "");
else
{
var root = _doc.CreateElement("Web");
_doc.AppendChild(root);
}
try
{
var el = (XmlElement)_doc.DocumentElement.AppendChild(_doc.CreateElement("Web"));
el.SetAttribute("Title", Title);
el.AppendChild(_doc.CreateElement("WebAddress")).InnerText = WebAddress;
el.AppendChild(_doc.CreateElement("IPAddress")).InnerText = IPAddress;
_doc.Save(@"" + LogFileName + "");
}
catch (Exception ex)
{
}
}