The problem with the code below is the directory is getting created on server but file is not getting created, when i run locally on my system then it runs fine, please suggest what can be done, this is my priority 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);
}
}
May be there is user permission problem but i’m trying that to.. giving folder every possible permission…
Actually the error was with
in my system the format was 22-05-2012 but on the server was 22\05\2012 so this was creating error on path not found…