public void TryGetValueOrExceptionString_Can_ReturnExceptionInfo() { ApplicationException exceptionToThrow = new ApplicationException("Threwn exception"); ExceptionWrapper.Returner <string> stringReturner = () => { throw exceptionToThrow; }; ExceptionWrapper.ExceptionConverter <string> exceptionConverter = ExceptionInfoProvider.GetExceptionInfo; string gottenString = ExceptionWrapper.TryGetValueOrExceptionString(stringReturner, exceptionConverter); string expected = ExceptionInfoProvider.GetExceptionInfo(exceptionToThrow); Assert.AreEqual <string>(expected, gottenString); }
public virtual void Log(LogLevel logLevel, Exception e, bool includeStackTrace, string format, params object[] args) { Log(logLevel, () => string.Format(format, args) + ". Exception: " + ExceptionInfoProvider.GetExceptionInfo(e, includeStackTrace) + "\r\n\r\n"); }
public virtual void Log(LogLevel logLevel, Exception e, string altMessage, bool includeStackTrace, int msgCode = 0) { Log(logLevel, () => altMessage + ". Exception: " + ExceptionInfoProvider.GetExceptionInfo(e, includeStackTrace) + "\r\n\r\n", msgCode); }
public virtual void Log(LogLevel logLevel, Exception e, bool includeStackTrace) { Log(logLevel, () => "Exception: " + ExceptionInfoProvider.GetExceptionInfo(e, includeStackTrace) + "\r\n\r\n"); }
public override bool CheckForAvailability(out Func <string> messageFunc) { int attempts = 0; Stopwatch stopWatch; DateTime time; retry: bool useLogging = InternetConnectionLogger != null; if (useLogging) { stopWatch = new Stopwatch(); time = DateTime.Now; stopWatch.Start(); } else { time = DateTime.MinValue; stopWatch = null; } try { attempts++; var webRequest = WebRequest.Create(URL_TO_CHECK); webRequest.Timeout = Timeout; using (var webResponse = webRequest.GetResponse()) { using (var responseStream = webResponse.GetResponseStream()) { if (useLogging) { stopWatch.Stop(); InternetConnectionLogger?.Log(time, true, stopWatch.ElapsedMilliseconds, $"#{attempts}"); } messageFunc = null; return(true); } } //using (var client = new WebClient()) //{ // using (client.OpenRead(URL_TO_CHECK)) // { // messageFunc = null; // return true; // } //} } catch (Exception ex) { if (useLogging) { stopWatch.Stop(); var errMsg = ExceptionInfoProvider.GetExceptionInfo(ex, false, false, false, false); messageFunc = () => errMsg; InternetConnectionLogger?.Log(time, false, stopWatch.ElapsedMilliseconds, $"#{attempts} " + errMsg); } else { messageFunc = () => ExceptionInfoProvider.GetExceptionInfo(ex, false, false, false, false); } if (attempts < 2) { goto retry; } return(false); } }