下面代码的问题是在服务器上创建了目录但没有创建文件,当我在我的系统上本地运行时它运行正常,请建议可以做什么,这是我的优先级 1。thnx
public static void CreateLog(string strToLog)
{
try
{
string excepfile = "CacheServerLogs_" + DateTime.Now.ToShortDateString().Replace("-", "_") + ".txt";
FileStream fs = null;
StreamWriter sw = null;
string mydocpath = "C:\\CacheServerLogs";
if (!Directory.Exists(mydocpath))
Directory.CreateDirectory(mydocpath);
string exceptionfile = Path.Combine(mydocpath, excepfile);
//string exceptionfile = mydocpath + "\\" + excepfile;
if (!File.Exists(exceptionfile))
fs = File.Create(exceptionfile);
else
sw = File.AppendText(exceptionfile);
sw = sw == null ? new StreamWriter(fs) : sw;
sw.WriteLine(DateTime.Now.ToString() + " - " + strToLog);
sw.Close();
if (fs != null)
fs.Close();
}
catch (Exception ex)
{
HandleException(ex);
}
}
可能存在用户权限问题,但我正在尝试这样做......给予文件夹所有可能的权限......