LoggingConfiguration

Namespace: NLog
We found 10 examples in language CSharp for this search. You will see 52 fragments of code.
		/// <summary>
		/// Loads logging settings from provided configuration and sets up logging pipeline.
		/// </summary>
		/// <param name="loggerFactory">The logger factory to configure.</param>
		/// <param name="setupSettings">The action for filling <see cref="LoggingSettings"/>.</param>
		/// <returns>The <see cref="ILoggerFactory"/> so that additional calls can be chained.</returns>
		public static ILoggerFactory AddLogging(this ILoggerFactory loggerFactory, Action<LoggingSettings> setupSettings)
		{
			return AddLogging(setupSettings, loggingConfiguration => loggingConfiguration.AddLogging(loggerFactory));
		}

		/// <summary>
		/// Loads logging settings from provided configuration and sets up logging pipeline.
		/// </summary>
		/// <param name="loggingBuilder">The logging builder to configure.</param>
		/// <param name="setupSettings">The action for filling <see cref="LoggingSettings"/>.</param>
		/// <returns>The <see cref="ILoggingBuilder"/> so that additional calls can be chained.</returns>
		public static ILoggingBuilder AddLogging(this ILoggingBuilder loggingBuilder, Action<LoggingSettings> setupSettings)
		{
			return AddLogging(setupSettings, loggingConfiguration => loggingConfiguration.AddLogging(loggingBuilder));
		}

		private static T AddLogging<T>(Action<LoggingSettings> setupSettings, Func<LoggingConfiguration, T> addLogging)
		{
			var loggingSettings = new LoggingSettings();
			setupSettings(loggingSettings);

			var loggingConfiguration = new LoggingConfiguration();
			loggingConfiguration.LoadSettings(loggingSettings);

			return addLogging(loggingConfiguration);
		}

using Machine.Specifications;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Serilog.Core;
using System;

using It = Machine.Specifications.It;

namespace BellRichM.Logging.Test
{
    public class LogManagerSpecs
    {
        protected static LoggingConfiguration loggingConfiguration;
        protected static LogManager logManager;

        Establish context = () =>
        {
            var configuration = new ConfigurationBuilder()
                .SetBasePath(AppContext.BaseDirectory)
                .AddJsonFile("testlogging.json")
                .Build();

            loggingConfiguration = new LoggingConfiguration();
            var loggingSection = configuration.GetSection("Logging");
            new ConfigureFromConfigurationOptions<LoggingConfiguration>(loggingSection)
                .Configure(loggingConfiguration);

            logManager = new LogManager(configuration);
        };
    }

    internal class When_instantiating_a_LogManager : LogManagerSpecs
    {
        It should_set_the_console_sink_filter_switch = () =>
          logManager.LoggingFilterSwitches.ConsoleSinkFilterSwitch.ToString()
            .ShouldEqual(loggingConfiguration.FilterSwitches.ConsoleSink.Expression);

        It should_set_the_default_level_switch = () =>
          logManager.LoggingLevelSwitches.DefaultLoggingLevelSwitch.MinimumLevel
            .ShouldEqual(loggingConfiguration.LevelSwitches.Default.Level);

        It should_set_the_microsoft_level_switch = () =>
          logManager.LoggingLevelSwitches.MicrosoftLoggingLevelSwitch.MinimumLevel
            .ShouldEqual(loggingConfiguration.LevelSwitches.Microsoft.Level);

        It should_set_the_system_level_switch = () =>
          logManager.LoggingLevelSwitches.SystemLoggingLevelSwitch.MinimumLevel
            .ShouldEqual(loggingConfiguration.LevelSwitches.System.Level);

        It should_set_the_console_sink_level_switch = () =>
          logManager.LoggingLevelSwitches.ConsoleSinkLevelSwitch.MinimumLevel
            .ShouldEqual(loggingConfiguration.LevelSwitches.ConsoleSink.Level);
    }

    internal class When_creating_a_Serilog_logger : LogManagerSpecs
    {
        protected static Logger logger;

        Because of = () =>
            logger = logManager.Create();

        It should_create_the_logger = () =>
          logger.ShouldNotBeNull();

        Cleanup after = () =>
            logger.Dispose();
    }
}

        [TestInitialize]
        public override void TestInitialize()
        {
            this.strPath = @".\LogConfig" + Guid.NewGuid().ToString();
            LogFileReader.CreateDirectory(this.strPath);
        }

        [TestCleanup]
        public override void Cleanup()
        {
            base.Cleanup();
        }

        private void UpdateConfigForRollingFlatFileRollExistsIncrement(LoggingConfiguration loggingConfiguration)
        {
            var rollingFlatFileTraceListener = new RollingFlatFileTraceListener(Path.Combine(strPath, "RollingFlatFile.log"), "----------------------------------------", "----------------------------------------", extendedFormatter, 1, "yyyy", RollFileExistsBehavior.Increment, RollInterval.None, 3);
            loggingConfiguration.AddLogSource("RollFFIncrement", SourceLevels.All, true, rollingFlatFileTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(rollingFlatFileTraceListener);
        }

        private void UpdateConfigForRollingFlatFileRollExistsOverwrite(LoggingConfiguration loggingConfiguration)
        {
            var rollingFlatFileTraceListener = new RollingFlatFileTraceListener(Path.Combine(strPath, "RollingFlatFile.log"), "----------------------------------------", "----------------------------------------", extendedFormatter, 0, String.Empty, RollFileExistsBehavior.Overwrite, RollInterval.None, 3);
            loggingConfiguration.AddLogSource("RollFFOverwrite", SourceLevels.All, true, rollingFlatFileTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(rollingFlatFileTraceListener);
        }

        [TestMethod]
        public void ArchiveFilesAreWrittenWhenAddingUnprocessedSourceForRollingFlatFile()
        {
            var config = new LoggingConfiguration();
            config.IsTracingEnabled = true;
            config.DefaultSource = "General";
            config.LogWarningsWhenNoCategoriesMatch = true;

            var rollingFlatFileTraceListener = new RollingFlatFileTraceListener(Path.Combine(strPath, @"TraceTest.log"),
                "----------------------------------------",
                "----------------------------------------",
                new TextFormatter("Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"),
                1, "yyyy", RollFileExistsBehavior.Increment, RollInterval.None, 3);

            config.SpecialSources.Unprocessed.Listeners.Add(rollingFlatFileTraceListener);
            this.writer = new LogWriter(config);

            this.writer.Write("Test Logging Rolling 1");
            this.writer.Write("Test Logging Rolling 2");
            this.writer.Write("Test Logging Rolling 3");
            this.writer.Write("Test Logging Rolling 4");
            this.writer.Write("Test Logging Rolling 5");
            this.writer.Write("Test Logging Rolling 6");
            this.writer.Dispose();

            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "TraceTest.log")));
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "TraceTest" + "." + DateTime.Now.Year + ".1" + ".log")));
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "TraceTest" + "." + DateTime.Now.Year + ".2" + ".log")));
        }

        [TestMethod]
        public void RollingFlatFileGeneralCategoryIncrement()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();
            this.UpdateConfigForRollingFlatFileRollExistsIncrement(loggingConfiguration);

            this.writer = new LogWriter(loggingConfiguration);
            for (int i = 0; i < 10; i++)
            {
                this.writer.Write("Test Logging Rolling " + i.ToString());
            }
            this.writer.Dispose();

            Assert.AreEqual(4, Directory.GetFiles(this.strPath).Length);
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile.log")));
            Assert.IsFalse(File.Exists(Path.Combine(this.strPath, "RollingFlatFile" + "." + DateTime.Now.Year + ".1" + ".log")));
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile" + "." + DateTime.Now.Year + ".2" + ".log")));
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile" + "." + DateTime.Now.Year + ".3" + ".log")));
            Assert.IsTrue(File.Exists(Path.Combine(this.strPath, "RollingFlatFile" + "." + DateTime.Now.Year + ".4" + ".log")));

            string strFileData = LogFileReader.ReadFileWithoutLock(Path.Combine(strPath, "RollingFlatFile.log"));

            Assert.IsTrue(strFileData.Contains("Message: Test Logging Rolling 8"));
            Assert.IsTrue(strFileData.Contains("Message: Test Logging Rolling 9"));
            Assert.IsTrue(strFileData.Contains("Category: General"));
        }

        [TestInitialize]
        public override void TestInitialize()
        {
        }

        [TestCleanup]
        public override void Cleanup()
        {
            base.Cleanup();
        }

        private void UpdateConfigForEventlog(LoggingConfiguration loggingConfiguration)
        {
            var eventLog = new EventLog("Application", ".", "Enterprise Library Logging");
            var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog);
            loggingConfiguration.AddLogSource("General", SourceLevels.All, true, eventLogTraceListener);
            loggingConfiguration.SpecialSources.LoggingErrorsAndWarnings.Listeners.Add(eventLogTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(eventLogTraceListener);
        }

        private void UpdateConfigForEventlogWithFormatter(LoggingConfiguration loggingConfiguration)
        {
            var eventLog = new EventLog("Application", ".", "Enterprise Library Logging");
            var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog, briefFormatter);
            loggingConfiguration.AddLogSource("General", SourceLevels.All, true, eventLogTraceListener);
            loggingConfiguration.SpecialSources.LoggingErrorsAndWarnings.Listeners.Add(eventLogTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(eventLogTraceListener);
        }

        private void UpdateConfigForEventlogSourceFormatter(LoggingConfiguration loggingConfiguration)
        {
            var eventLogTraceListener = new FormattedEventLogTraceListener("Enterprise Library Logging", briefFormatter);
            loggingConfiguration.AddLogSource("General", SourceLevels.All, true, eventLogTraceListener);
            loggingConfiguration.SpecialSources.LoggingErrorsAndWarnings.Listeners.Add(eventLogTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(eventLogTraceListener);
        }

        private void UpdateConfigForEventlogSourceLogFormatter(LoggingConfiguration loggingConfiguration)
        {
            var eventLogTraceListener = new FormattedEventLogTraceListener("Enterprise Library Logging", "Application", briefFormatter);
            loggingConfiguration.AddLogSource("General", SourceLevels.All, true, eventLogTraceListener);
            loggingConfiguration.SpecialSources.LoggingErrorsAndWarnings.Listeners.Add(eventLogTraceListener);
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(eventLogTraceListener);
        }


        [TestInitialize]
        public override void TestInitialize()
        {
            this.strPath = @".\LogConfig" + Guid.NewGuid().ToString();
            LogFileReader.CreateDirectory(this.strPath);
        }

        [TestCleanup]
        public override void Cleanup()
        {
            base.Cleanup();
        }

        private void UpdateFlatFileForConfig(LoggingConfiguration loggingConfiguration)
        {
            // Trace Listeners
            var flatFileTraceListener = new FlatFileTraceListener(Path.Combine(strPath, "FlatFile.log"), "----------------------------------------", "----------------------------------------", briefFormatter);
            flatFileTraceListener.Filter = new EventTypeFilter(SourceLevels.All);

            // Special Sources Configuration
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(flatFileTraceListener);
        }

        private void UpdateFlatFileForConfigNullParams(LoggingConfiguration loggingConfiguration)
        {
            // Trace Listeners
            var flatFileTraceListener = new FlatFileTraceListener(Path.Combine(strPath, "FlatFile.log"), null, null, null);
            flatFileTraceListener.Filter = new EventTypeFilter(SourceLevels.All);

            // Special Sources Configuration
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(flatFileTraceListener);
        }

        private void UpdateFlatFileForConfigStreamWriter(LoggingConfiguration loggingConfiguration)
        {
            // Trace Listeners
            StreamWriter writer = new StreamWriter(Path.Combine(strPath, "FlatFileStreamWriter.log"));
            FlatFileTraceListener flatFileTraceListener = new FlatFileTraceListener(writer);

            flatFileTraceListener.Filter = new EventTypeFilter(SourceLevels.All);

            // Special Sources Configuration
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(flatFileTraceListener);
        }

        private void UpdateFlatFileForConfigFileStream(LoggingConfiguration loggingConfiguration)
        {
            // Trace Listeners
            FileStream stream = new FileStream(Path.Combine(strPath, "FlatFileFileStream.log"), FileMode.OpenOrCreate);
            FlatFileTraceListener flatFileTraceListener = new FlatFileTraceListener(stream);

            //var flatFileTraceListener = new FlatFileTraceListener(Path.Combine(strPath, "FlatFile.log", "----------------------------------------", "----------------------------------------", briefFormatter);
            flatFileTraceListener.Filter = new EventTypeFilter(SourceLevels.All);

            // Special Sources Configuration
            loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(flatFileTraceListener);
        }


        /// <summary>
        /// Log an message consisting of args with log level trace
        /// </summary>
        /// <param name="logEntry"></param>
        public void Trace(LogEntry logEntry)
        {
            if (LoggingConfiguration == null || LoggingConfiguration.MinimumLevel <= LogLevel.Trace)
                InternalLog(logEntry, LogLevel.Trace);
        }

        /// <summary>
        /// Log an message consisting of args with log level trace
        /// </summary>
        /// <param name="message"></param>
        public void Trace(string message)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Log an message consisting of args with log level debug
        /// </summary>
        /// <param name="logEntry"></param>
        public void Debug(LogEntry logEntry)
        {
            if (LoggingConfiguration == null || LoggingConfiguration.MinimumLevel <= LogLevel.Debug)
                InternalLog(logEntry, LogLevel.Debug);
        }

        /// <summary>
        /// Log an message with log level debug
        /// </summary>
        /// <param name="message"></param>
        public void Debug(string message)
        {
            if (LoggingConfiguration == null || LoggingConfiguration.MinimumLevel <= LogLevel.Debug)
                InternalLog(new LogEntry { Message = message }, LogLevel.Debug);
        }

        /// <summary>
        /// Log an message consisting of args with log level info
        /// </summary>
        /// <param name="logEntry"></param>
        public void Info(LogEntry logEntry)
        {
            if (LoggingConfiguration == null || LoggingConfiguration.MinimumLevel <= LogLevel.Info)
                InternalLog(logEntry, LogLevel.Info);
        }

        /// <summary>
        /// Log an message consisting of args with log level info
        /// </summary>
        /// <param name="message"></param>
        public void Info(string message)
        {
            throw new NotImplementedException();
        }

        [TestMethod]
        public void AddsLogSourceToCollection()
        {
            var config = new LoggingConfiguration();
            config.AddLogSource("mock", new MockTraceListener());

            Assert.AreEqual<int>(1, config.LogSources["mock"].Listeners.Count);
        }

        [TestMethod]
        public void TracingIsEnabledByDefault()
        {
            var config = new LoggingConfiguration();

            Assert.IsTrue(config.IsTracingEnabled);
        }

        [TestMethod]
        public void FiltersListIsNotNull()
        {
            var config = new LoggingConfiguration();

            Assert.IsNotNull(config.Filters);
        }

        [TestMethod]
        public void SpecialLogSourcesAreNotNull()
        {
            var config = new LoggingConfiguration();

            Assert.IsNotNull(config.SpecialSources.AllEvents);
            Assert.IsNotNull(config.SpecialSources.LoggingErrorsAndWarnings);
            Assert.IsNotNull(config.SpecialSources.Unprocessed);
        }

        [TestMethod]
        public void LogSourcesCollectionIsNotNull()
        {
            var config = new LoggingConfiguration();

            Assert.IsNotNull(config.LogSources);
        }

        [TestMethod]
        public void LoggingIsEnabledByDefault()
        {
            var config = new LoggingConfiguration();

            Assert.IsTrue(config.IsLoggingEnabled);
        }


        #region Methods

        public static void CloseAndFlush()
        {
            Log.CloseAndFlush();
        }

        public static void ConfigureConsoleLoggerSink(LoggerConfiguration loggerConfig, LoggingConfiguration loggingConfiguration)
        {
            if (!loggingConfiguration.WriteToConsole)
            {
                return;
            }

            if (loggingConfiguration.UseCompactFormatter)
            {
                loggerConfig.WriteTo.Console(loggingConfiguration.TextFormatter, loggingConfiguration.LogLevel, loggingConfiguration.LevelSwitch, loggingConfiguration.StandardErrorFromLevel);
            }
            else
            {
                loggerConfig.WriteTo.Console(
                    loggingConfiguration.LogLevel,
                    loggingConfiguration.OutputTemplate,
                    loggingConfiguration.FormatProvider,
                    loggingConfiguration.LevelSwitch,
                    loggingConfiguration.StandardErrorFromLevel,
                    loggingConfiguration.Theme);
            }
        }

        public static void ConfigureFileLoggerSink(LoggerConfiguration loggerConfig, LoggingConfiguration loggingConfiguration)
        {
            if (string.IsNullOrEmpty(loggingConfiguration.LogFile))
            {
                return;
            }

            var fullPath = loggingConfiguration.AbsoluteLogFilePath;

            if (loggingConfiguration.UseCompactFormatter)
            {
                loggerConfig.WriteTo.File(loggingConfiguration.TextFormatter, fullPath,
                    rollingInterval: loggingConfiguration.RollingInterval,
                    retainedFileCountLimit: loggingConfiguration.RetainedFileCountLimit,
                    rollOnFileSizeLimit: loggingConfiguration.RollOnFileSizeLimit);
            }
            else
            {
                loggerConfig.WriteTo.File(fullPath,
                    rollingInterval: loggingConfiguration.RollingInterval,
                    retainedFileCountLimit: loggingConfiguration.RetainedFileCountLimit,
                    rollOnFileSizeLimit: loggingConfiguration.RollOnFileSizeLimit);
            }
        }

        public static CloudWatchSinkOptions GetCloudWatchSinkOptionsFromConfig(LoggingConfiguration loggingConfiguration)
        {
            var options = new CloudWatchSinkOptions
            {
                // the name of the CloudWatch Log group from config  
                LogGroupName = loggingConfiguration.LogGroup,
                TextFormatter = loggingConfiguration.TextFormatter,
                MinimumLogEventLevel = loggingConfiguration.LogLevel,
                BatchSizeLimit = loggingConfiguration.BatchSizeLimit,
                QueueSizeLimit = loggingConfiguration.QueueSizeLimit,
                Period = loggingConfiguration.Period,
                CreateLogGroup = loggingConfiguration.CreateLogGroup,
                LogStreamNameProvider = loggingConfiguration.LogStreamNameProvider,
                RetryAttempts = loggingConfiguration.RetryAttempts,
                LogGroupRetentionPolicy = loggingConfiguration.RetentionPolicy
            };
            return options;
        }

        /// <summary>
        /// Alows for an injectible logger such as with Asp.net core, etc.
        /// </summary>
        /// <param name="logger"></param>
        public static void InitializeLogger(ILogger logger)
        {
            if (isInitialized)
            {
                return;
            }

            lock (LockObj)
            {
                if (isInitialized)
                {
                    Debug.Assert(false, "Logger is already initialized. This request will be ignored!");
                    return;
                }

                Log.Logger = logger;
                isInitialized = true;
            }
        }

        public static void InitializeLoggerFromConfig()
        {
            if (isInitialized)
            {
                return;
            }

            lock (LockObj)
            {
                if (isInitialized)
                {
                    Debug.Assert(false, "Logger is already initialized. This request will be ignored!");
                    return;
                }

                var logConfig = new LoggerConfiguration().ReadFrom.AppSettings();
                Log.Logger = logConfig.CreateLogger();
                isInitialized = true;
            }
        }


        private void LogForConfiguration(LoggingConfiguration c, string s)
        {
            var m = c.GetPrefix(c.GetTimePrefix()) + s;
            LoggingHelper.ForegroundColorWriteLine(m, c.Color);
            Addition.ProcessMessage(m, c.Color);
        }


        /// <summary>
        /// logs a string as debug
        /// </summary>
        /// <param name="s">string to log</param>
        public void Debug(string s)
        {
            LogForConfiguration(DebugConfiguration, s);
        }

        /// <summary>
        /// logs a string as error
        /// </summary>
        /// <param name="s">string to log</param>
        public void Error(string s)
        {
            LogForConfiguration(ErrorConfiguration, s);
        }


        /// <summary>
        /// gets addition
        /// </summary>
        /// <returns>addition</returns>
        public ILoggingAddition GetAddition()
        {
            return Addition;
        }

        /// <summary>
        /// gets debug configuration
        /// </summary>
        /// <returns>debug configuration</returns>
        public LoggingConfiguration GetDebugConfiguration()
        {
            return DebugConfiguration;
        }

        /// <summary>
        /// gets error configuration
        /// </summary>
        /// <returns>error configuration</returns>
        public LoggingConfiguration GetErrorConfiguration()
        {
            return ErrorConfiguration;
        }


        [TestInitialize]
        public override void TestInitialize()
        {
            LogFileReader.CreateDirectory("mail");
        }

        [TestCleanup]
        public override void Cleanup()
        {
            base.Cleanup();
        }

        private void UpdateConfigForEmailNoPortFormatterEmailAuth(LoggingConfiguration loggingConfiguration)
        {
            if ((string.IsNullOrEmpty(this.fromaddress) || string.IsNullOrEmpty(this.toaddress) || string.IsNullOrEmpty(this.smtpserver)))
            {
                Assert.Inconclusive("Cannot run tests because SMTP server parameters are missing");
            }
            else
            {
                EmailTraceListener emailListener = new EmailTraceListener(this.toaddress,
                                                            this.fromaddress,
                                                            "StartOfSubject",
                                                            "EndOfSubject", this.smtpserver);

                emailListener.Filter = new EventTypeFilter(SourceLevels.All);
                loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener);
                loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener);
            }
        }

        private void UpdateConfigForEmailNoPortEmailAuth(LoggingConfiguration loggingConfiguration)
        {
            if ((string.IsNullOrEmpty(this.fromaddress) || string.IsNullOrEmpty(this.toaddress) || string.IsNullOrEmpty(this.smtpserver)))
            {
                Assert.Inconclusive("Cannot run tests because SMTP server parameters are missing");
            }
            else
            {
                EmailTraceListener emailListener = new EmailTraceListener(this.toaddress,
                                                            this.fromaddress,
                                                            "StartOfSubject",
                                                            "EndOfSubject", this.smtpserver, new TextFormatter());

                emailListener.Filter = new EventTypeFilter(SourceLevels.All);
                loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener);
                loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener);
            }
        }

        private void UpdateConfigForEmailNoFormatterEmailAuth(LoggingConfiguration loggingConfiguration)
        {
            if ((string.IsNullOrEmpty(this.fromaddress) || string.IsNullOrEmpty(this.toaddress) || string.IsNullOrEmpty(this.smtpserver)))
            {
                Assert.Inconclusive("Cannot run tests because SMTP server parameters are missing");
            }
            else
            {
                EmailTraceListener emailListener = new EmailTraceListener(this.toaddress,
                                                            this.fromaddress,
                                                            "StartOfSubject",
                                                            "EndOfSubject", this.smtpserver, this.smtpport);

                emailListener.Filter = new EventTypeFilter(SourceLevels.All);
                loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener);
                loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener);
            }
        }

        private void UpdateConfigForEmailNoEmailAuth(LoggingConfiguration loggingConfiguration)
        {
            if ((string.IsNullOrEmpty(this.fromaddress) || string.IsNullOrEmpty(this.toaddress) || string.IsNullOrEmpty(this.smtpserver)))
            {
                Assert.Inconclusive("Cannot run tests because SMTP server parameters are missing");
            }
            else
            {
                EmailTraceListener emailListener = new EmailTraceListener(this.toaddress,
                                                            this.fromaddress,
                                                            "StartOfSubject",
                                                            "EndOfSubject", this.smtpserver, this.smtpport, new TextFormatter());

                emailListener.Filter = new EventTypeFilter(SourceLevels.All);
                loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener);
                loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener);
            }
        }

NLog.Config.LoggingConfiguration : Object

Constructors :

public LoggingConfiguration()
public LoggingConfiguration(LogFactory logFactory = )

Methods :

public LogFactory get_LogFactory()
public Boolean get_ExceptionLoggingOldStyle()
public Void set_ExceptionLoggingOldStyle(Boolean value = )
public IDictionary<String, SimpleLayout> get_Variables()
public ReadOnlyCollection<Target> get_ConfiguredNamedTargets()
public IEnumerable<String> get_FileNamesToWatch()
public IList<LoggingRule> get_LoggingRules()
public CultureInfo get_DefaultCultureInfo()
public Void set_DefaultCultureInfo(CultureInfo value = )
public ReadOnlyCollection<Target> get_AllTargets()
public Void AddTarget(Target target = )
public Void AddTarget(String name = , Target target = )
public Target FindTargetByName(String name = )
public TTarget FindTargetByName(String name = )
public Void AddRule(LogLevel minLevel = , LogLevel maxLevel = , String targetName = , String loggerNamePattern = *)
public Void AddRule(LogLevel minLevel = , LogLevel maxLevel = , Target target = , String loggerNamePattern = *)
public Void AddRule(LogLevel minLevel = , LogLevel maxLevel = , Target target = , String loggerNamePattern = , Boolean final = )
public Void AddRuleForOneLevel(LogLevel level = , String targetName = , String loggerNamePattern = *)
public Void AddRuleForOneLevel(LogLevel level = , Target target = , String loggerNamePattern = *)
public Void AddRuleForOneLevel(LogLevel level = , Target target = , String loggerNamePattern = , Boolean final = )
public Void AddRuleForAllLevels(String targetName = , String loggerNamePattern = *)
public Void AddRuleForAllLevels(Target target = , String loggerNamePattern = *)
public Void AddRuleForAllLevels(Target target = , String loggerNamePattern = , Boolean final = )
public LoggingRule FindRuleByName(String ruleName = )
public Boolean RemoveRuleByName(String ruleName = )
public LoggingConfiguration Reload()
public Void RemoveTarget(String name = )
public Void Install(InstallationContext installationContext = )
public Void Uninstall(InstallationContext installationContext = )
public String ToString()
public Type GetType()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods