Ejemplo n.º 1
0
        private void checkLogFilterButton_Click(object sender, EventArgs e)
        {
            FilterQueryForm filterQueryForm = new FilterQueryForm();

            DialogResult result = filterQueryForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    DisplayScenarioStart(Properties.Resources.CheckFilterStartMessage);

                    ICollection <string> categories = filterQueryForm.Categories;
                    int    priority = filterQueryForm.Priority;
                    string names    = GetCategoriesString(categories);

                    this.resultsTextBox.Text += "Log enabled filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the logging enabled filter to determine if logging is enabled.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter <LogEnabledFilter>().Enabled)
                    {
                        // Logging is enabled.
                        this.resultsTextBox.Text += "Logging is enabled." + Environment.NewLine;
                    }
                    else
                    {
                        // Logging is not enabled. Events will not be logged. Your application can avoid the performance
                        // penalty of collecting information for an event that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "Logging is not enabled." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Category filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the category filter to determine if the categories selected by the
                    // user would pass the filter check.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter <CategoryFilter>().ShouldLog(categories))
                    {
                        // Event will be logged according to currently configured filters.
                        // Perform operations (possibly expensive) to gather information for the
                        // event to be logged. For this QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "The selected categories (" + names + ") pass filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collecting information for an event that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "The selected categories (" + names + ") do not pass filter check." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Priority filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the priority filter to determine if the priority selected by the
                    // user would pass the filter check.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter <PriorityFilter>().ShouldLog(priority))
                    {
                        // Perform possibly expensive operations gather information for the
                        // event to be logged. For the QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "The selected priority (" + priority.ToString() + ") passes the filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collection information for an even that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "The selected priority (" + priority.ToString() + ") does not pass the filter check." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Event check" + Environment.NewLine;
                    this.resultsTextBox.Text += "===========" + Environment.NewLine;

                    // Create a new log entry to demonstrate how to query if an existing log
                    // entry will be logged.
                    LogEntry logEntry = new LogEntry();
                    logEntry.Message  = "Demonstrate filter check";
                    logEntry.Priority = priority;
                    logEntry.EventId  = 100;

                    foreach (string category in categories)
                    {
                        logEntry.Categories.Add(category);
                    }

                    // ----------------------------------------------------------------------
                    // Query the Logger class to determine if an event with the
                    // specified priority and categories would pass the filter checks.
                    // ----------------------------------------------------------------------
                    if (Logger.ShouldLog(logEntry))
                    {
                        // Perform possibly expensive operations gather information for the
                        // event to be logged. For the QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "An event with the selected priority (" + priority.ToString() + ") and " +
                                                    "categories (" + names + ") passes the filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collection information for an even that will not be
                        // loggeed.
                        if (!Logger.GetFilter <LogEnabledFilter>().Enabled)
                        {
                            this.resultsTextBox.Text += "Logging is not enabled. The event will not be logged." + Environment.NewLine;
                        }
                        else
                        {
                            this.resultsTextBox.Text += "An event with the selected priority (" + priority.ToString() + ") and " +
                                                        "categories (" + names + ") does not pass the filter check." + Environment.NewLine;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProcessUnhandledException(ex);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Ejemplo n.º 2
0
        private void checkLogFilterButton_Click(object sender, EventArgs e)
        {
            FilterQueryForm filterQueryForm = new FilterQueryForm();

            DialogResult result = filterQueryForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    DisplayScenarioStart(Properties.Resources.CheckFilterStartMessage);

                    ICollection<string> categories = filterQueryForm.Categories;
                    int priority = filterQueryForm.Priority;
                    string names = GetCategoriesString(categories);

                    this.resultsTextBox.Text += "Log enabled filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the logging enabled filter to determine if logging is enabled.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter<LogEnabledFilter>().Enabled)
                    {
                        // Logging is enabled.
                        this.resultsTextBox.Text += "Logging is enabled." + Environment.NewLine;
                    }
                    else
                    {
                        // Logging is not enabled. Events will not be logged. Your application can avoid the performance
                        // penalty of collecting information for an event that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "Logging is not enabled." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Category filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the category filter to determine if the categories selected by the
                    // user would pass the filter check.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter<CategoryFilter>().ShouldLog(categories))
                    {
                        // Event will be logged according to currently configured filters.
                        // Perform operations (possibly expensive) to gather information for the
                        // event to be logged. For this QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "The selected categories (" + names + ") pass filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collecting information for an event that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "The selected categories (" + names + ") do not pass filter check." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Priority filter check" + Environment.NewLine;
                    this.resultsTextBox.Text += "==================" + Environment.NewLine;

                    // ----------------------------------------------------------------------
                    // Query the priority filter to determine if the priority selected by the
                    // user would pass the filter check.
                    // ----------------------------------------------------------------------
                    if (Logger.GetFilter<PriorityFilter>().ShouldLog(priority))
                    {
                        // Perform possibly expensive operations gather information for the
                        // event to be logged. For the QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "The selected priority (" + priority.ToString() + ") passes the filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collection information for an even that will not be
                        // loggeed.
                        this.resultsTextBox.Text += "The selected priority (" + priority.ToString() + ") does not pass the filter check." + Environment.NewLine;
                    }

                    this.resultsTextBox.Text += Environment.NewLine;
                    this.resultsTextBox.Text += "Event check" + Environment.NewLine;
                    this.resultsTextBox.Text += "===========" + Environment.NewLine;

                    // Create a new log entry to demonstrate how to query if an existing log
                    // entry will be logged.
                    LogEntry logEntry = new LogEntry();
                    logEntry.Message = "Demonstrate filter check";
                    logEntry.Priority = priority;
                    logEntry.EventId = 100;

                    foreach (string category in categories)
                    {
                        logEntry.Categories.Add(category);
                    }

                    // ----------------------------------------------------------------------
                    // Query the Logger class to determine if an event with the
                    // specified priority and categories would pass the filter checks.
                    // ----------------------------------------------------------------------
                    if (Logger.ShouldLog(logEntry))
                    {
                        // Perform possibly expensive operations gather information for the
                        // event to be logged. For the QuickStart, we simply display the
                        // result of the query.
                        this.resultsTextBox.Text += "An event with the selected priority (" + priority.ToString() + ") and " +
                            "categories (" + names + ") passes the filter check." + Environment.NewLine;
                    }
                    else
                    {
                        // Event will not be logged. You application can avoid the performance
                        // penalty of collection information for an even that will not be
                        // loggeed.
                        if (!Logger.GetFilter<LogEnabledFilter>().Enabled)
                        {
                            this.resultsTextBox.Text += "Logging is not enabled. The event will not be logged." + Environment.NewLine;
                        }
                        else
                        {
                            this.resultsTextBox.Text += "An event with the selected priority (" + priority.ToString() + ") and " +
                                "categories (" + names + ") does not pass the filter check." + Environment.NewLine;
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProcessUnhandledException(ex);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }