Debug() public method

Logs the specified debug message.
public Debug ( [ message ) : void
message [ The message.
return void
Esempio n. 1
0
        /// <summary>
        /// Performs uninstallation which requires administrative permissions.
        /// </summary>
        /// <param name="installationContext">The installation context.</param>
        public void Uninstall(InstallationContext installationContext)
        {
            string categoryName = this.CategoryName;

            if (PerformanceCounterCategory.Exists(categoryName))
            {
                installationContext.Debug("Deleting category '{0}'", categoryName);
                PerformanceCounterCategory.Delete(categoryName);
            }
            else
            {
                installationContext.Debug("Category '{0}' does not exist.", categoryName);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Performs installation which requires administrative permissions.
        /// </summary>
        /// <param name="installationContext">The installation context.</param>
        public void Install(InstallationContext installationContext)
        {
            // categories must be installed together, so we must find all PerfCounter targets in the configuration file
            var countersByCategory = this.LoggingConfiguration.AllTargets.OfType<PerformanceCounterTarget>().BucketSort(c => c.CategoryName);
            string categoryName = this.CategoryName;

            if (countersByCategory[categoryName].Any(c => c.created))
            {
                installationContext.Trace("Category '{0}' has already been installed.", categoryName);
                return;
            }

            try
            {
                PerformanceCounterCategoryType categoryType;
                CounterCreationDataCollection ccds = GetCounterCreationDataCollection(countersByCategory[this.CategoryName], out categoryType);

                if (PerformanceCounterCategory.Exists(categoryName))
                {
                    installationContext.Debug("Deleting category '{0}'", categoryName);
                    PerformanceCounterCategory.Delete(categoryName);
                }

                installationContext.Debug("Creating category '{0}' with {1} counter(s) (Type: {2})", categoryName, ccds.Count, categoryType);
                foreach (CounterCreationData c in ccds)
                {
                    installationContext.Trace("  Counter: '{0}' Type: ({1}) Help: {2}", c.CounterName, c.CounterType, c.CounterHelp);
                }

                PerformanceCounterCategory.Create(categoryName, "Category created by NLog", categoryType, ccds);
            }
            catch (Exception exception)
            {
                if (exception.MustBeRethrown())
                {
                    throw;
                }

                if (installationContext.IgnoreFailures)
                {
                    installationContext.Warning("Error creating category '{0}': {1}", categoryName, exception.Message);
                }
                else
                {
                    installationContext.Error("Error creating category '{0}': {1}", categoryName, exception.Message);
                    throw;
                }
            }
            finally
            {
                foreach (var t in countersByCategory[categoryName])
                {
                    t.created = true;
                }
            }
        }