示例#1
0
        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);
            };
        }
示例#2
0
        public void CapturedErrorHasCodeMismatchTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsFalse(ce.HasCode("Level-1", "Flip"));
        }
示例#3
0
        public void CapturedErrorHasCodeTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsTrue(ce.HasCode("Level-1", "Cap"));
        }
示例#4
0
        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");
        }
示例#5
0
        public void CapturedErrorHasCodeWithNoParametersTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsTrue(ce.HasCode());
        }
示例#6
0
        public void CapturedErrorCodeAtIndexIsNegativeTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsTrue(ce.CodeAt(-1) is null);
        }
示例#7
0
        public void CapturedErrorMessageTest()
        {
            var ce = new CapturedError();

            ce.ErrorMessage("It's too late");
            Assert.IsTrue(ce.Message == "It's too late");
        }
示例#8
0
        public void CapturedErrorIsCodeMismatchValueTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsFalse(ce.IsCode("Level-1", "Cap", 14));
        }
示例#9
0
        public void CapturedErrorCodeAtIndexTooBigTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsTrue(ce.CodeAt(3) is null);
        }
示例#10
0
        public void CapturedErrorIsCodeObjectTypeDifferenceTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsFalse(ce.IsCode("Level-1", "Cap", "12"));
        }
示例#11
0
        public void CapturedErrorIsCodeSoughtTooLongTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsFalse(ce.IsCode("Level-1", "Cap", 12, "Too long"));
        }
示例#12
0
        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));
        }
示例#13
0
        public void CapturedErrorHasACategoryTest()
        {
            var ce = new CapturedError("Testing");

            Assert.IsTrue(ce.IsOK);
            Assert.IsFalse(ce.IsErrored);
            Assert.IsTrue(ce.Category == "Testing");
        }
示例#14
0
        public void CapturedErrorSettingCodeFlagsErrorTest()
        {
            var ce = new CapturedError();

            ce.ErrorCode("Level-1", "Cap", 12);
            Assert.IsFalse(ce.IsOK);
            Assert.IsTrue(ce.IsErrored);
        }
示例#15
0
        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);
        }
示例#16
0
        public void CapturedErrorOKTest()
        {
            var ce = new CapturedError();

            Assert.IsTrue(ce.IsOK);
            Assert.IsFalse(ce.IsErrored);
            Assert.IsTrue(ce.Category == "");
            Assert.IsTrue(ce.Message == "");
        }
示例#17
0
        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);
        }