Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"><see cref="bool"/></param>
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                Trace.Flush();
                Trace.Listeners.Clear();

                //--
                // put the call to deal with house cleaning here

                if (this.PTMRunLogFileManager != null)
                {
                    this.PTMRunLogFileManager.Dispose();
                    this.PTMRunLogFileManager = null;
                }
            }

            // Free any unmanaged objects here.
            disposed = true;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="logFilePath"></param>
        /// <param name="dtLastRun"></param>
        public PolartecErrorLog(string applicationId, string logFilePath, DateTime dtLastRun)
        {
            if (applicationId != string.Empty || applicationId != null)
            {
                _dtReference   = DateTime.UtcNow;
                _applicationID = applicationId;
                string[] arrayInfo = { $@"{_applicationID}", $@"{_dtReference.Ticks.ToString()}", $@"{_intRefileCount}" };
                //stringLogFileName = string.Format(PolartecErrorLog.stringLogFileNameFormat, _applicationID, DateTime.UtcNow.Ticks.ToString());
                stringLogFileName         = string.Format(PolartecErrorLog.stringLogFileNameFormat, arrayInfo);
                stringLogFilePath         = $@"{logFilePath}\{Application.ProductName}_ErrorLogs";
                stringFullNamePathLogFile = string.Format("{0}\\{1}", stringLogFilePath, stringLogFileName);

                try
                {
                    // --
                    // Check Log File Directory - create if not there
                    DirectoryInfo directoryInfoErrorLog = new DirectoryInfo(stringLogFilePath);
                    if (!directoryInfoErrorLog.Exists)
                    {
                        directoryInfoErrorLog.Create();
                    }
                }
                catch (Exception excpt)
                {
                    MessageBox.Show($@"Exception occurred in Error Log -> msg = {excpt.Message} ; with stack trace = {excpt.StackTrace}");
                }

                Trace.Listeners.Clear();
                Trace.Listeners.Add(new DefaultTraceListener());
                Trace.Listeners.Add(new TextWriterTraceListener(stringFullNamePathLogFile));// create a trace listener as a run log

                if (dtLastRun == null)
                {
                    dtLastRun = DateTime.Now;
                }

                this.PTMRunLogFileManager = new PolartecErrorLogFileManager(dtLastRun, PolartecErrorLog.stringLogFileNameFormat, stringLogFilePath);
            }
            else
            {
                ArgumentNullException argNullExcpt = new ArgumentNullException("applicationId",
                                                                               "The constructor parameter 'string applicationId' was passed either null or empty, when it was expected to be an initialized string object.");
                throw argNullExcpt;
            }
        }