Ejemplo n.º 1
0
        private static (ILogger, IDisposable) InitializeLogger()
        {
            var config = new NLog.Config.LoggingConfiguration();

            // Targets where to log to: File and Console
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "log.txt"
            };
            var logconsole = new NLog.Targets.ConsoleTarget("logconsole");

            var dispose = new AnonymousDisposable(() =>
            {
                logfile.Dispose();
                logconsole.Dispose();
            });

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Error, LogLevel.Fatal, logfile);

            // Apply config
            NLog.LogManager.Configuration = config;

            return(NLog.LogManager.GetCurrentClassLogger(), dispose);
        }
Ejemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="WrongURLLogger"/> class.</summary>
        public WrongURLLogger()
        {
            this.Logger = LogManager.GetCurrentClassLogger();
            var config = new NLog.Config.LoggingConfiguration();

            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "logfile.txt"
            };
            var logConsole = new NLog.Targets.ConsoleTarget("logConsole");

            config.AddRule(LogLevel.Info, LogLevel.Fatal, logConsole);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
            logConsole.Dispose();
            logfile.Dispose();
            NLog.LogManager.Configuration = config;
        }