public void Error(Exception p_ex, string p_message) { // this was an Exception. That is important. Write it to the Console too, not only the log file string str = $"{DateTime.UtcNow.ToString("MMdd'T'HH':'mm':'ss.fff")}#{Thread.CurrentThread.ManagedThreadId}#{LogLevel.Error}: {p_message}, : EXCEPTION: {p_ex.ToStringWithShortenedStackTrace(400)}"; Console.WriteLine(str); WriteToFileVerbatim(str); }
// all the exceptions are sent, because they are important Even if many happens in a 30 minutes period public static void SendException(string p_locationMsg, Exception e, HealthMonitorMessageID p_healthMonId) { //Utils.Logger.Warn($"HealthMonitorMessage.SendException(). Crash in { p_locationMsg}. Exception Message: '{ e.Message}', StackTrace: { e.StackTrace}"); Utils.Logger.Warn($"HealthMonitorMessage.SendException(): Exception occured in {p_locationMsg}. Exception: '{ e.ToString()}'"); if (!(new HealthMonitorMessage() { ID = p_healthMonId, ParamStr = $"Exception in {p_locationMsg}. Exception: '{ e.ToStringWithShortenedStackTrace(400)}'", ResponseFormat = HealthMonitorMessageResponseFormat.None }.SendMessage().Result)) { Utils.Logger.Error("Error in sending HealthMonitorMessage to Server."); } }