public Logger(IComponentContext components) { _logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", $"Automaton_{Assembly.GetEntryAssembly().GetName().Version}_{string.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars()))}.log"); Task.Factory.StartNew(LoggerController); if (File.Exists(_logPath)) { File.Delete(_logPath); } var platformType = Environment.Is64BitOperatingSystem ? "x64" : "x86"; var headerString = $"Automaton/{Assembly.GetEntryAssembly().GetName().Version} ({Environment.OSVersion.VersionString}; {platformType}) {RuntimeInformation.FrameworkDescription}"; WriteLine($"{DateTime.Now} {headerString}"); WriteLine($"{DateTime.Now} Is admin: {new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)}"); WriteLine($"{DateTime.Now} Automaton Start"); AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => { var stackTrace = new StackTrace(eventArgs.Exception); var frame = stackTrace.GetFrame(stackTrace.FrameCount - 1); //stackTrace.FrameCount - 1 WriteLine($"LineNumber: {frame.GetFileLineNumber()}, FilenName: {frame.GetFileName()}, MethodName: {frame.GetMethod().Name}\n{eventArgs.Exception.StackTrace} {eventArgs.Exception.Message}"); if (eventArgs.Exception.Message.Contains("materialDesign")) { return; } CapturedError.Invoke(this, eventArgs); }; }
public void CapturedErrorHasCodeMismatchTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsFalse(ce.HasCode("Level-1", "Flip")); }
public void CapturedErrorHasCodeTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.HasCode("Level-1", "Cap")); }
public void CapturedErrorMessageWithParamsTest() { var ce = new CapturedError(); ce.ErrorMessage("It's too late {0} and {1}", "p1", 2); Assert.IsTrue(ce.Message == "It's too late p1 and 2"); }
public void CapturedErrorHasCodeWithNoParametersTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.HasCode()); }
public void CapturedErrorCodeAtIndexIsNegativeTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.CodeAt(-1) is null); }
public void CapturedErrorMessageTest() { var ce = new CapturedError(); ce.ErrorMessage("It's too late"); Assert.IsTrue(ce.Message == "It's too late"); }
public void CapturedErrorIsCodeMismatchValueTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsFalse(ce.IsCode("Level-1", "Cap", 14)); }
public void CapturedErrorCodeAtIndexTooBigTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.CodeAt(3) is null); }
public void CapturedErrorIsCodeObjectTypeDifferenceTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsFalse(ce.IsCode("Level-1", "Cap", "12")); }
public void CapturedErrorIsCodeSoughtTooLongTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsFalse(ce.IsCode("Level-1", "Cap", 12, "Too long")); }
public void CapturedErrorSetMessageAndCodeTest() { var ce = new CapturedError(); ce.ErrorMessage("It's too late").ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.Message == "It's too late"); Assert.IsTrue(ce.HasCode("Level-1", "Cap", 12)); }
public void CapturedErrorHasACategoryTest() { var ce = new CapturedError("Testing"); Assert.IsTrue(ce.IsOK); Assert.IsFalse(ce.IsErrored); Assert.IsTrue(ce.Category == "Testing"); }
public void CapturedErrorSettingCodeFlagsErrorTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsFalse(ce.IsOK); Assert.IsTrue(ce.IsErrored); }
public void CapturedErrorCodeAtOKTest() { var ce = new CapturedError(); ce.ErrorCode("Level-1", "Cap", 12); Assert.IsTrue(ce.CodeAt(2) is int); Assert.IsTrue((int)ce.CodeAt(2) == 12); }
public void CapturedErrorOKTest() { var ce = new CapturedError(); Assert.IsTrue(ce.IsOK); Assert.IsFalse(ce.IsErrored); Assert.IsTrue(ce.Category == ""); Assert.IsTrue(ce.Message == ""); }
public void CapturedErrorSettingMessageFlagsErrorTest() { var ce = new CapturedError(); ce.ErrorMessage("It's too late"); var s = ce.Message; Assert.IsFalse(ce.IsOK); Assert.IsTrue(ce.IsErrored); }