PhaseLogEntry is a class that encapsulates all the data we're writing in Phase Logging PhaseLogging is an activity that is done by the DataMigration tool to cope with the fact that phases of the process may be done by C#, but other phases (e.g. Sql Server - based PostProcessing modules) that will not be able to write to log4net. This will be consumed by IPhaseLogWriter implementations as a unified way to show what happened on a given run of the DataMigration tool.
Esempio n. 1
0
        /// <summary>
        /// Logs the StageLogEntry to the implementation-specific persistence mechanism.
        /// In this implementation, it logs to a Sql Table (DataMigrationPhaseLog) in the cpms
        /// database in Sql Server.
        /// </summary>
        /// <param name="entry">A StageLogEntry with all the information needed to produce
        /// a useful stage log entry.</param>
        public void Log(PhaseLogEntry entry)
        {
            entries.Add(entry);
            var sqlCommand = String.Format(sqlCommandFormat,
                tableName,
                entry.LogSource,
                String.IsNullOrEmpty(entry.DataSourceCode) ? "null" : entry.DataSourceCode,
                entry.LoadNumber.HasValue ? entry.LoadNumber.ToString() : "null",
                entry.PhaseNumber,
                entry.NumberOfRecords.HasValue ?
                    entry.NumberOfRecords.Value.ToString() : "null",
                entry.Description.Replace("'", "''")); // Use two single quotes.

            // It is useful to redundantly use the log4net log.
            log.Debug(entry.Description);

            try {
                using (var connection = new SqlConnection(ConnectionString)) {
                    connection.Open();

                    using (var command = new SqlCommand(sqlCommand, connection)) {
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex) {
                // We're not going to fail the load for this, but we want it to be clear.
                log.ErrorFormat("Log - error attempting to log staging message = {0}",
                                ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calls into Sql to get the actual list of Phase Log Entries.  The cached set that
        /// we have is just an in-memory backup strategy, in case this fails.  It only has the
        /// phase log entries that were done from the C#, not the ones done by T-SQL based
        /// Post-Processing stages.   If this function is successful, it replaces the cached
        /// list of entries, so the entries can be more complete.
        /// </summary>
        /// <param name="loadNumber">Load number.</param>
        void AttemptToLoadTheEntriesStoresInSql(int loadNumber)
        {
            if (loadNumber == -1) {
                // Probably an error got caught before a loadnumber could be propagated back
                // to the MonitoringPublisher.   This is fine, the PhaseLog entries are a nice
                //-to-have, but not essential.
                return;
            }
            var sqlCommand = String.Format("select * from DataMigrationPhaseLog where " +
                                        "loadnumber= {0} order by RecordDate", loadNumber);
            try {
                using (var connection = new SqlConnection(ConnectionString)) {
                    connection.Open();

                    using (var command = new SqlCommand(sqlCommand, connection)) {
                        var entriesFromSql = new List<PhaseLogEntry>();
                        var reader = command.ExecuteReader();
                        while (reader.Read()) {
                            var entry = new PhaseLogEntry();
                            entry.LogSource = (int) reader["LogSource"];
                            entry.DataSourceCode = (string) reader["DataSourceCode"];
                            entry.LoadNumber = loadNumber;
                            entry.PhaseNumber = GetNullableNumericField(reader, "Phase");
                            entry.NumberOfRecords = GetNullableNumericField(reader,
                                                                        "NumberOfRecords");
                            entry.Description = (string) reader["Description"];

                            entriesFromSql.Add(entry);
                        }
                        // We succeeded, so replace the cached list of entries with ones from
                        // Sql, which are more complete.
                        entries = entriesFromSql;
                    }
                }
            }
            catch (Exception ex) {
                // We're not going to fail the load for this, but we want it to be clear.
                log.ErrorFormat("Log - error attempting to log staging message = {0}",
                                ex.Message);
            }
        }