Exemplo n.º 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();
 }
Exemplo n.º 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();
        }
Exemplo n.º 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));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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");
        }
Exemplo n.º 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)
                {
                }
            }
        }
Exemplo n.º 7
0
 static void Main()
 {
     LogEntry entry = new LogEntry("Test data with special characters !\"#%&/()=?`¨'רזו,.", LogPriority.Information, new FlatFileAppender(), true);
     Console.WriteLine(entry.Message);
     Console.Read();
 }
Exemplo n.º 8
0
 public void SmtpAppender()
 {
     LogEntry logEntry = new LogEntry("Test Data", LogPriority.Information, new SmtpAppender(), false);
     logEntry.WriteToLog();
 }
Exemplo n.º 9
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();
 }