下面的代码问题在于目录正在服务器上创建, 但是文件没有被创建, 当我在系统上本地运行时, 它运行正常, 请建议可以做什么, 这是我的优先级 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);
}
}
可能存在用户权限问题, 但我尝试这样做... 给文件夹所有可能的许可...