Ask a questionAsk a question
 

AnswerLogging from webpart to a text file

  • Friday, November 06, 2009 3:21 PMKiran J Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    I wanted to log Exceptions and some information from my webpart code to a text file on server's layouts folder. I tried with the code below and got an error. The reason for my writing log to file under layouts folder is, I wanted to view log files from browser using http:// domain name / _layouts/subfolder/filname.txt .


    using (StreamWriter swLog = File.AppendText(LogFilePath))
    {
     swLog.WriteLine(logContent.ToString());
     swLog.Flush();
     swLog.Close();
    }

    Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Any help please..

Answers

All Replies