好的,所以我正在尝试为在 ASP.net 和 C# 上运行的网站提供错误日志文件。
我尝试使用常规路径存储驱动器。期待它,因为它在 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
}
此代码将在本地机器上生成文件,而不是在服务器上