0

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?

Community
  • 1
  • 1
user2255811
  • 496
  • 2
  • 8
  • 19
  • What permissions have you assigned the user? I beleive the AppPool user requires FullControl permissions to the logs folder in order to create a new file if one does not already exist. – RJ Lohan Sep 23 '13 at 01:37
  • @RJLohan I haven't granted it full control but I have given it read & execute, write, modify and list folder contents. I will try full control and see if that helps – user2255811 Sep 23 '13 at 01:52
  • You're catching and throwing away exceptions, remove your `try catch` block and see if an exception is being raised. Also have you spelled your path name correctly? `C:/Web_Srvice_Logs/` -> `C:\Web_Service_Logs\`. – Kev Sep 23 '13 at 04:10

1 Answers1

0

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.

John Koerner
  • 37,428
  • 8
  • 84
  • 134