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) { } }
/// <summary> /// Inserts the message into a log file /// </summary> /// <param name="ex"></param> /// <param name="logFilePath"></param> public static void Log(string ex, string logFilePath) { string errorMessage = ex; ErrorLogHelper.WriteLog(errorMessage, logFilePath, String.Empty); }