好吧,所以我想爲運行在ASP.net和C#上的網站提供錯誤日誌文件。如何在服務器上存儲文件ASP.net
我試過用常規路徑存儲驅動器。 期待它,因爲它是在C#代碼(頁面後面的代碼)它會拿起服務器並將其存儲在那裏。 (最終它是在服務器上執行的代碼)
不幸的是,對我來說那不是真的。它被保存在客戶端打開網站的本地機器上。
如何強制它被保存在服務器機器上?
我想在一個地方的所有錯誤日誌。 關於閱讀或如何做到這一點的任何建議。
string path = "C:\\WebSite";
string error = "error";
try
{
// check if dir exists if it does i add file name to the path
// i removed code to keep it simple
path += "\\logs.txt";
FileStream log_fs =
new FileStream(path, FileMode.Append, FileAccess.Write);
StreamWriter log_sw =
new StreamWriter(log_fs);
string log = String.Empty;
// formate log string using error message
log_sw.Write(log);
log_sw.Close();
log_fs.Close();
}
catch (Exception ex)
{
// here I e-mail the error in case logging failed
}
此代碼將生成的,而不是服務器的本地計算機上的文件,
代碼示例請嗎? – cjk 2009-07-09 15:27:47