예제 #1
0
        public void LogErrorToJsonInputAsync()
        {
            var textInput = "e6d64ac2-c8e9-45e0-ac73-3298ff8cb96f";
            LogglyConfiguration.Configure(c => c.AuthenticateWith("csharptests", "Passw0rd!"));

            var logger = new Logger(textInput);
            var randomString = GenerateRandomString(8);
            logger.LogError(randomString, new InvalidOperationException("oops" + randomString + " something went wrong"));

            var signal = new AutoResetEvent(false);
            SearchJsonResponse response = null;

            new Thread(() =>
            {
                var running = true;
                while (running)
                {
                    Thread.Sleep(3000);
                    response = new Searcher("csharptests").SearchJson("exception", "oops" + randomString);

                    if (response.TotalRecords > 0)
                        running = false;
                }

                signal.Set();
            }).Start();

            signal.WaitOne(50 * 1000); // wait till loggly index the new event (if it didn't after 50 seconds it is broken)

            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.TotalRecords);
            Assert.AreEqual(randomString, response.Results[0].Json["message"]);
            Assert.AreEqual("error", response.Results[0].Json["category"]);
            Assert.AreEqual("System.InvalidOperationException: oops" + randomString + " something went wrong", response.Results[0].Json["exception"]);
        }
예제 #2
0
 public void LogErrorTest()
 {
     Scrabble.Logger tempLog = new Logger();
     tempLog.LogError("Error...", "Unit Test");
     string inFile = System.IO.File.ReadAllText(System.IO.Directory.GetCurrentDirectory() + "\\Logs\\" + tempLog.now + "_VERBOSE_LOG.txt");
     Console.Write(inFile);
     Assert.IsFalse(inFile.Equals("!!!!!!!ERROR - " + "Unit Test" + ": " + "Error..." + " !!!!!!!"));
 }
예제 #3
0
        public void LoggerLogsError()
        {
            // Setup
            IDocumentStore store = Global.GetInMemoryStore();
            Logger logger = new Logger(store);

            DateTime date = DateTime.Now;
            Exception exception = new Exception("Here is the message");

            // Act
            logger.LogError(exception, "StoryNotFoundInRepository");

            // Assert
            using (var session = store.OpenSession())
            {
                LogError savedError = (from e in session.Query<LogError>() select e).First();
                Assert.GreaterOrEqual(savedError.DateOfOccurence, date.AddMinutes(-1));
                Global.PropertyValuesAreEquals(exception, savedError.Exception);
                Assert.AreEqual(savedError.ErrorCode, "StoryNotFoundInRepository");
            }
        }