AlarmWorkflow.Shared.Diagnostics.ExceptionIntervalLogger.LogFormat C# (CSharp) Метод

LogFormat() публичный Метод

Ability to log the exception as formatted text.
public LogFormat ( Exception ex, LogType type, object source, string format ) : void
ex System.Exception The exception.
type LogType The message type.
source object The component from which this type comes. The type name of the instance is used.
format string The text to use as the format string.
Результат void
        public void LogFormat(Exception ex, LogType type, object source, string format, params object[] arguments)
        {
            if (ShouldLogException(ex))
            {
                Logger.Instance.LogFormat(type, source, format, arguments);
            }
        }

Usage Example

        void IAlarmSource.RunThread()
        {
            var intervalLogger = new ExceptionIntervalLogger(TimeSpan.FromMinutes(10));
            while (true)
            {
                try
                {
                    //.tif or .pdf
                    FileInfo[] files = _faxPath.GetFiles("*.*", SearchOption.TopDirectoryOnly)
                                .Where(_ => _.Name.EndsWith(".tif", StringComparison.InvariantCultureIgnoreCase) || _.Name.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase))
                                .ToArray();

                    if (files.Length > 0)
                    {
                        Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.BeginProcessingFaxes, files.Length);

                        foreach (FileInfo file in files)
                        {
                            if(file.Extension == ".pdf")
                            {
                                ProcessNewPdf(file);
                            }
                            else
                            {
                                ProcessNewImage(file);
                            }
                        }

                        Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.ProcessingFaxesComplete);
                    }
                    intervalLogger.ResetExceptionCollection();
                    Thread.Sleep(RoutineIntervalMs);
                }
                catch(Exception ex)
                {
                    intervalLogger.LogFormat(ex, LogType.Warning, this, Properties.Resources.FaxDirAccessError, _faxPath.FullName, ex.ToString());
                }
            }
        }