public static void WriteLog(string errorMessage, string directryPath, string errorDescription = "") { string FileName = string.Empty; string FilePath = string.Empty; try { // create directory if not exists try { if (!Directory.Exists(directryPath)) { Directory.CreateDirectory(directryPath); } } catch (Exception) { throw; } // Make file Name FileName = ErrorLogHelper.GetFileName(); // Make a FilePath FilePath = Path.Combine(directryPath, FileName) + ".txt"; try { //If file exists then append the text , otherwise create a file and insert the text if (!File.Exists(FilePath)) { File.WriteAllText(FilePath, " "); } } catch (Exception) { } ErrorLogHelper.WriteErrorInLogFile(FilePath, errorMessage, errorDescription); } catch (Exception) { } }