Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogTracer"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 public LogTracer(string name)
 {
     _name = name;
     _entry = new LogEntry("starting: " + _name, LogPriority.Information, new FlatFileAppender(), false);
     _entry.IsTracer = true;
     _entry.WriteToLog();
 }
Example #2
0
        public void SqlServerAppender()
        {
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoggingServer"].ConnectionString);
            sqlConn.Open();

            SqlCommand sqlDelete = new SqlCommand("DELETE FROM Logs", sqlConn);
            sqlDelete.ExecuteNonQuery();

            sqlConn.Close();

            LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new SqlServerAppender(), false);
            logEntry.WriteToLog();

            sqlConn.Open();
            
            SqlCommand sqlCmd = new SqlCommand("SELECT * FROM Logs", sqlConn);
            SqlDataReader rdr = sqlCmd.ExecuteReader();

            Assert.AreEqual(true, rdr.HasRows);
            
            while (rdr.Read())
            {
                Assert.AreEqual((string)rdr["LogMessage"], "Test Data", "The log message was not Test Data");
            }
            sqlConn.Close();
        }
Example #3
0
        public void FlatFileAppender()
        {
            LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new FlatFileAppender(), false);
            logEntry.WriteToLog();

            Assert.AreEqual(true, File.Exists(logEntry.FullPath));
            File.Delete(logEntry.FullPath);
            Assert.AreEqual(false, File.Exists(logEntry.FullPath));
        }
Example #4
0
        public void EventLogAppender()
        {
            if (EventLog.SourceExists("Tests"))
                EventLog.DeleteEventSource("Tests");

            LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new EventLogAppender(), false);
            logEntry.WriteToLog();

            Assert.AreEqual(true, EventLog.SourceExists("Tests"));
        }
Example #5
0
        public void XmlFileAppender()
        {
            LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new XmlFileAppender(), false);
            logEntry.WriteToLog();

            Assert.AreEqual(true, File.Exists(logEntry.FullPath), "XML file does not exist");

            // Clean up
            File.Delete(logEntry.FullPath);

            Assert.AreEqual(false, File.Exists(logEntry.FullPath), "XML file does still exist");
        }
Example #6
0
        public void MsmqAppender()
        {
            LogEntry logEntry = new LogEntry("Test", LogPriority.Warning, new MsmqAppender(), false);
            logEntry.WriteToLog();

            using (MessageQueue mq = new MessageQueue(ConfigurationManager.AppSettings["MsmqPath"]))
            {
                try
                {
                    Message message = mq.Receive();
                    Assert.AreEqual(message.Body, "Test");
                }
                catch (Exception e)
                {
                }
            }
        }
Example #7
0
 public void SmtpAppender()
 {
     LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new SmtpAppender(), false);
     logEntry.WriteToLog();
 }
Example #8
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _entry = new LogEntry("shutting down: " + _name, LogPriority.Information, new FlatFileAppender(), false);
     _entry.IsTracer = true;
     _entry.WriteToLog();
 }