简体   繁体   English

C#,iis7 Web服务器未写入日志文件

[英]C#, iis7 web server not writing log files

I'm trying to get my web server to write logs to a txt file on the server. 我正在尝试让我的Web服务器将日志写入服务器上的txt文件。 It should be simple and it is working fine on my development machine but it doesn't on the server. 它应该很简单,并且可以在我的开发机器上正常工作,但不能在服务器上工作。 I have followed he advice in this: IIS7 Permissions Overview - ApplicationPoolIdentity 我遵循他的建议: IIS7权限概述-ApplicationPoolIdentity

But it still won't write. 但是它仍然不会写。 the path is correct and it should have the proper permissions after following the above link. 路径正确,点击上面的链接后,它应该具有适当的权限。 my code for writing the file is: 我写文件的代码是:

 private void Logger(String lines)
    {
        String fileName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + "_Logs.txt";

        try
        {
            System.IO.StreamWriter file = new System.IO.StreamWriter("C:/Web_Srvice_Logs/" + fileName, true);
            file.WriteLine(lines + " " + DateTime.Now.ToString());

            file.Close();
        }
        catch (Exception) { }

any Ideas? 有任何想法吗?

Catch the exception and check the value. 捕获异常并检查值。 My guess is that the App Pool user does not have rights to write to that directory (I know you said you checked it) and/or that directory does not exist. 我的猜测是,App Pool用户没有写该目录的权限(我知道您说过您已检查过该目录)和/或该目录不存在。 The error message you are getting will help diagnose it. 您收到的错误消息将有助于对其进行诊断。

You could always set the app pool to an admin user to test if it is a permission problem. 您可以始终将应用程序池设置为管理员用户,以测试是否存在权限问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM