예제 #1
0
        public void ElmahXmlParser_ParseStackTrace_GetList()
        {
            // arrange
            var expectedList = new Dictionary<Guid, string>() { { _guid1, "System.Web.HttpException (0x80004005): Exception Message.&#xD;&#xA;   at Namespace1.ClassName1.Method(string something1)&#xD;&#xA;   at System.Web.Handlers.ProcessRequest(Params params)" }, { _guid2, "System.Web.HttpException (0x80004005): Exception Message.&#xD;&#xA;   at Namespace2.ClassName2.Method(string something2)&#xD;&#xA;   at System.Web.Handlers.ProcessRequest(Params params)" }, };
            var helper = new Mock<IFileHelper>();
            var errorsXmlFileName = "errors.xml";
            helper.Setup(x => x.ReadAllLines(errorsXmlFileName)).Returns(new[] {
                string.Format("{{{0}}},detail=\"System.Web.HttpException (0x80004005): Exception Message.&#xD;&#xA;   at Namespace1.ClassName1.Method(string something1)&#xD;&#xA;   at System.Web.Handlers.ProcessRequest(Params params)\"    ", _guid1.ToString()),
                string.Format("{{{0}}},detail=\"System.Web.HttpException (0x80004005): Exception Message.&#xD;&#xA;   at Namespace2.ClassName2.Method(string something2)&#xD;&#xA;   at System.Web.Handlers.ProcessRequest(Params params)\"    ", _guid2.ToString()),
            });
            var parser = new ElmahXmlParser(helper.Object);

            // act
            var actualList = parser.GetStackTraceList(errorsXmlFileName);

            // assert
            Assert.That(actualList, Is.Not.Empty, "Empty List");
            Assert.That(actualList, Is.EquivalentTo(expectedList), "Wrong List");
        }
예제 #2
0
파일: Program.cs 프로젝트: johnhilts/utils
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting parser engine ...");

            var parser = new ElmahXmlParser(new FileHelper());
            parser.FlattenFileContents("errors.xml");
            var scriptNameList = parser.GetScriptNameList("flatErrors.xml");
            var stackTraceList = parser.GetStackTraceList("flatErrors.xml");
            var userAgentList = parser.GetUserAgentList("flatErrors.xml");
            var outputLines = new StringBuilder("ID\tPage\tStackTrace\tUserAgent\r\n");
            var count = scriptNameList.Count;
            Console.WriteLine("Page Count: {0}\r\nStack Trace Count: {1}\r\nUser Agent Count: {2}", count, stackTraceList.Count, userAgentList.Count);
            foreach (var item in scriptNameList)
            {
                if (stackTraceList.ContainsKey(item.Key) && userAgentList.ContainsKey(item.Key))
                    outputLines.AppendFormat("{0}\t{1}\t{2}\t{3}\r\n", item.Key, item.Value, stackTraceList[item.Key], userAgentList[item.Key]);
                else
                    Console.WriteLine("Missing key: " + item.Key);
            }
            File.WriteAllText("formattedErrors.txt", outputLines.ToString());

            Console.WriteLine("Parsing Complete.");
        }