我有一個最近的問題。我可以在我的intetpub/wwwrooot /文件夾寫一個日誌文件
上傳文件,但我不能在這同一個文件夾寫入日誌文件...
我對網絡業務的所有權限。一切都在我的服務器上。
DirectoryInfo di = new DirectoryInfo(~/);
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();
string strLogText = di;
// Create a writer and open the file:
StreamWriter log;
if (!System.IO.File.Exists("C:\\inetpub\\wwwroot\\logfile.txt"))
{
log = new StreamWriter("C:\\inetpub\\wwwroot\\logfile.txt");
}
else
{
log = System.IO.File.AppendText("C:\\inetpub\\wwwroot\\logfile.txt");
}
// Write to the file:
log.WriteLine(DateTime.Now);
log.WriteLine(strLogText);
log.WriteLine();
// Close the stream:
log.Close();
錯誤是訪問被拒絕!
它在本地工作,但在我的服務器上它沒有。在文件夾Inetpub上,我只需要允許寫入網絡服務?這很奇怪,因爲我可以上傳文件和寫入已經啓用
在這種情況下定義「不能」。你怎麼試試?它在代碼中嗎?顯示代碼。你有錯誤嗎?顯示錯誤。 – David
我編輯了我的第一篇文章。 – Kiwimoisi
我相信你有理由實施自己的日誌記錄。但是,您可能想要查看log4net - http://logging.apache.org/log4net/ –