/// <summary> /// Method that receives the player's email /// </summary> /// <param name="obj">The telegram data</param> /// <param name="exception">The exception to log</param> public static void Log(object obj, Exception exception) { string date = DateTime.Now.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH:mm:ss"); string path = "Log/log-" + date + ".txt"; string pathDirectory = "Log"; try { if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } StreamWriter streamWriter = new StreamWriter(path, true); StackTrace stacktrace = new StackTrace(); streamWriter.WriteLine(obj.GetType().FullName + " " + time); streamWriter.WriteLine(stacktrace.GetFrame(1).GetMethod().Name + " - " + exception.ToString()); streamWriter.WriteLine(""); streamWriter.Flush(); streamWriter.Close(); } catch (IOException exceptionLog) { TelegramBot.SendToTelegram(exceptionLog); } }
public static void SendToTelegram(string exception) { try { string menssage = "Error message: " + exception; telegramBotClient.SendTextMessageAsync(idGroup, menssage); } catch (IOException ioException) { TelegramBot telegramBot = new TelegramBot(); LogException.Log(telegramBot, ioException); } }
/// <summary> /// This method sends the exception to telegram /// </summary> /// <param name="exception">The exception to send</param> public static void SendToTelegram(Exception exception) { try { string menssage = "Error message: " + exception.Message; if (exception.InnerException != null) { menssage = menssage + "\nInner exception: " + exception.InnerException.Message; } menssage = menssage + "\nStack trace: " + exception.StackTrace; telegramBotClient.SendTextMessageAsync(idGroup, menssage); } catch (IOException ioException) { TelegramBot telegramBot = new TelegramBot(); LogException.Log(telegramBot, ioException); } }