在Web Service中我建了一个错误处理日志类,在出现错误,写入文件时,不能访问目录!急昐解决!!!

在Web Service中我建了一个错误处理日志类,当一个Web Service出现错误时,调用这个错误处理类,当运行到创建目录或文件时,系统报不能访问目录。这个错误处理类如下:
public class Log
{
public static void AppendLog(string args)
{
try
{
string FilePath="log\\Variables.txt";
string logTitle = "["+DateTime.Now.Year+"-"+DateTime.Now.Month+
"-"+DateTime.Now.Day+" "+DateTime.Now.TimeOfDay.ToString().Substring(0,8)
+"] ";
Directory.CreateDirectory("log");//在执行到此时出错,目录不能访问
//注消此代码时,在下一行代码也报错,信息差不多相同。改为此
//string FilePath="Variables.txt";
FileStream fs =
new FileStream(FilePath, FileMode.Append, FileAccess.Write, FileShare.Write);
fs.Close();
StreamWriter sw=new StreamWriter(FilePath, true, Encoding.Default);
sw.WriteLine(logTitle+args);
sw.Close();
}
catch(Exception ex)
{
Console.Write(ex.StackTrace);
Console.Write(ex.Source);
Console.Write(ex.Message);
}
}
}
---------------------------------------------------------------

Windows 2000 和 Windows XP :应用程序运行的帐户是ASPNET
Windows Server 2003 : NETWORK SERVICE。

检查一下对应你程序的用户权限,是否有读写文件的权限。

---------------------------------------------------------------

是的,应该权限不够
---------------------------------------------------------------

mark
---------------------------------------------------------------

帮顶
只求给分
---------------------------------------------------------------

http://www.cnblogs.com/tonyjoule/archive/2004/05/21/10821.aspx
你可以看看此文,试着做做

Published At
Categories with Web编程
Tagged with
comments powered by Disqus