简体   繁体   中英

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. 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

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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