Пример #1
0
        /// <summary>
        /// Loads the given <paramref name="logFileToLoad"/> into a new logger window.
        /// </summary>
        /// <param name="logFileToLoad">The log file to load into a new logger window.</param>
        /// <param name="verbose">[Optional] <c>True</c> to inform the user about any load error, otherwise <c>false</c>. Default is <c>True</c>.</param>
        private void LoadFileIntoLogger(string logFileToLoad, bool verbose = true)
        {
            if (!string.IsNullOrEmpty(logFileToLoad) && File.Exists(logFileToLoad))
            {
                ReceiverBase[] knownFileReceiver =
                {
                    new Log4NetFileReceiver(logFileToLoad, true)
                    ,                                      new SyslogFileReceiver(logFileToLoad, true)
                };

                foreach (ReceiverBase receiver in knownFileReceiver)
                {
                    if (receiver.CanHandleLogFile())
                    {
                        FrmLogDocument newFileDocument = new FrmLogDocument(receiver);

                        // Disable continues logging by default.
                        newFileDocument.Active = false;

                        // Show the new document.
                        newFileDocument.Show(mainDockPanel);

                        // Add the file to the recently used stack.
                        MruManager.AddFile(logFileToLoad);

                        // Rebuild the MRU list to ensure the opened file is displayed in the menu.
                        RebuildMruList();

                        return;
                    }
                }

                if (verbose)
                {
                    // Inform the user about the error.
                    MessageBox.Show(this, string.Format(
                                        Resources.strOpenLogFileError
                                        , Path.GetFileName(logFileToLoad))
                                    , Application.ProductName
                                    , MessageBoxButtons.OK
                                    , MessageBoxIcon.Error);
                }
            }
        }