Exemplo n.º 1
0
        private bool ValidateParameters(LogEntry logEntry)
        {
            bool             valid            = true;
            DatabaseSinkData databaseSinkData = loggingConfigurationView.GetSinkData(ConfigurationName) as DatabaseSinkData;

            if (databaseSinkData == null)
            {
                valid = false;
            }

            if (databaseSinkData.DatabaseInstanceName == null ||
                databaseSinkData.DatabaseInstanceName.Length == 0)
            {
                valid = false;
            }

            if (databaseSinkData.StoredProcName == null ||
                databaseSinkData.StoredProcName.Length == 0)
            {
                valid = false;
            }

            if (!valid)
            {
                logEntry.AddErrorMessage(SR.DatabaseSinkMissingParameters);
                this.defaultSink.SendMessage(logEntry);
            }

            return(valid);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates node with specified configuration data.
 /// </summary>
 /// <param name="databaseSinkData">Configuration data.</param>
 public DatabaseSinkNode(DatabaseSinkData databaseSinkData)
     : base(databaseSinkData)
 {
     this.databaseSinkData = databaseSinkData;
     this.onInstanceNodeRemoved = new ConfigurationNodeChangedEventHandler(OnInstanceNodeRemoved);
     this.onInstanceNodeRenamed = new ConfigurationNodeChangedEventHandler(OnInstanceNodeRenamed);
 }
Exemplo n.º 3
0
        private void ExecuteStoredProcedure(LogEntry logEntry)
        {
            DatabaseSinkData        databaseSinkData = loggingConfigurationView.GetSinkData(ConfigurationName) as DatabaseSinkData;
            DatabaseProviderFactory factory          = new DatabaseProviderFactory(loggingConfigurationView.ConfigurationContext);

            Data.Database    db  = factory.CreateDatabase(databaseSinkData.DatabaseInstanceName);
            DBCommandWrapper cmd = db.GetStoredProcCommandWrapper(databaseSinkData.StoredProcName);

            cmd.AddInParameter("eventID", DbType.Int32, logEntry.EventId);
            cmd.AddInParameter("category", DbType.String, logEntry.Category);
            cmd.AddInParameter("priority", DbType.Int32, logEntry.Priority);
            cmd.AddInParameter("severity", DbType.String, logEntry.Severity.ToString());
            cmd.AddInParameter("title", DbType.String, logEntry.Title);
            cmd.AddInParameter("timestamp", DbType.DateTime, logEntry.TimeStamp);
            cmd.AddInParameter("machineName", DbType.String, logEntry.MachineName);
            cmd.AddInParameter("AppDomainName", DbType.String, logEntry.AppDomainName);
            cmd.AddInParameter("ProcessID", DbType.String, logEntry.ProcessId);
            cmd.AddInParameter("ProcessName", DbType.String, logEntry.ProcessName);
            cmd.AddInParameter("ThreadName", DbType.String, logEntry.ManagedThreadName);
            cmd.AddInParameter("Win32ThreadId", DbType.String, logEntry.Win32ThreadId);
            cmd.AddInParameter("message", DbType.String, logEntry.Message);
            cmd.AddInParameter("formattedmessage", DbType.String, FormatEntry(logEntry));

            db.ExecuteNonQuery(cmd);
        }
Exemplo n.º 4
0
        public void GetDatabaseSinkFromConfigFile()
        {
            DistributorSettings settings = (DistributorSettings)ConfigurationManager.GetConfiguration(DistributorSettings.SectionName);
            DatabaseSinkData    dbData   = settings.SinkDataCollection["DatabaseSink2"] as DatabaseSinkData;

            Assert.AreEqual("LoggingDb", dbData.DatabaseInstanceName);
            Assert.AreEqual("WriteLog", dbData.StoredProcName);
        }
Exemplo n.º 5
0
        public void Constructor()
        {
            DatabaseSinkData sinkParams = new DatabaseSinkData();

            sinkParams.DatabaseInstanceName = "LoggingDb";
            sinkParams.StoredProcName       = "WriteLog";
            this.sink = CreateSink(sinkParams);
            DatabaseSink sink = CreateSink(sinkParams);

            Assert.IsNotNull(sink);
        }
Exemplo n.º 6
0
        public void DatabaseSinkDataPropertiesTest()
        {
            DatabaseSinkData data = new DatabaseSinkData();
            string           databaseInstanceName = "Service Name";
            string           storedProcName       = "spTest";

            data.DatabaseInstanceName = databaseInstanceName;
            data.StoredProcName       = storedProcName;

            Assert.AreEqual(databaseInstanceName, data.DatabaseInstanceName);
            Assert.AreEqual(storedProcName, data.StoredProcName);
        }
Exemplo n.º 7
0
        public void DatabaseSinkDataPropertiesTest()
        {
            DatabaseSinkData data = new DatabaseSinkData();
            string databaseInstanceName = "Service Name";
            string storedProcName = "spTest";

            data.DatabaseInstanceName = databaseInstanceName;
            data.StoredProcName = storedProcName;

            Assert.AreEqual(databaseInstanceName, data.DatabaseInstanceName);
            Assert.AreEqual(storedProcName, data.StoredProcName);
        }
Exemplo n.º 8
0
        public void DataTest()
        {
            string storedProcName = "psTest";

            DatabaseSinkData data = new DatabaseSinkData();
            data.StoredProcName = storedProcName;

            DatabaseSinkNode node = new DatabaseSinkNode(data);
            CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration());
            DatabaseSinkData nodeData = (DatabaseSinkData)node.SinkData;

            Assert.AreEqual(storedProcName, nodeData.StoredProcName);
        }
Exemplo n.º 9
0
        public void DataTest()
        {
            string storedProcName = "psTest";

            DatabaseSinkData data = new DatabaseSinkData();

            data.StoredProcName = storedProcName;

            DatabaseSinkNode node = new DatabaseSinkNode(data);

            CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration());
            DatabaseSinkData nodeData = (DatabaseSinkData)node.SinkData;

            Assert.AreEqual(storedProcName, nodeData.StoredProcName);
        }
Exemplo n.º 10
0
        public void Setup()
        {
            DatabaseSinkData sinkParams = new DatabaseSinkData();

            sinkParams.DatabaseInstanceName = "LoggingDb";
            sinkParams.StoredProcName       = "WriteLog";
            this.sink = CreateSink(sinkParams);

            string           sql = "delete from Log";
            DBCommandWrapper cmd = db.GetSqlStringCommandWrapper(sql);

            db.ExecuteNonQuery(cmd);

            CommonUtil.ResetEventLogCounter();
        }
Exemplo n.º 11
0
        public void NullServiceName()
        {
            DatabaseSinkData sinkParams = new DatabaseSinkData();

            sinkParams.DatabaseInstanceName = null;
            sinkParams.StoredProcName       = "stored proc";

            // create a flatfile sink without the required parameters
            DatabaseSink badSink = CreateSink(new DatabaseSinkData());

            CommonUtil.SendTestMessage(badSink);

            // confirm an error message was written to event log
            Assert.AreEqual(1, CommonUtil.EventLogEntryCount());

            string expected = SR.DatabaseSinkMissingParameters;
            string entry    = CommonUtil.GetLastEventLogEntry();

            Assert.IsTrue(entry.IndexOf(expected) > -1, "confirm error message");
        }
Exemplo n.º 12
0
 /// <summary>
 /// Creates node with specified configuration data.
 /// </summary>
 /// <param name="databaseSinkData">Configuration data.</param>
 public DatabaseSinkNode(DatabaseSinkData databaseSinkData) : base(databaseSinkData)
 {
     this.databaseSinkData      = databaseSinkData;
     this.onInstanceNodeRemoved = new ConfigurationNodeChangedEventHandler(OnInstanceNodeRemoved);
     this.onInstanceNodeRenamed = new ConfigurationNodeChangedEventHandler(OnInstanceNodeRenamed);
 }