Exemplo n.º 1
0
		private DebugTarget GetDebugTarget(LogLevel level)
		{
			DebugTarget debugTarget = new DebugTarget();
			debugTarget.Layout = "${message}";
			SimpleConfigurator.ConfigureForTargetLogging(debugTarget, level);
			return debugTarget;
		}
Exemplo n.º 2
0
        public NLogTracerWriterTests()
        {
            // setup writer under test
            _writer = new NLogTraceWriter();

            // setup debug logging target
            _debugTarget = new DebugTarget { Layout = "${message}" };
            SimpleConfigurator.ConfigureForTargetLogging(_debugTarget, LogLevel.Info);
        }
        public WebApiRequestRendererTests()
        {
            EnsureLayoutRendersSetup.Please();

            // setup writer under test
            _writer = new NLogTraceWriter();

            // setup debug logging target
            _debugTarget = new DebugTarget { Layout = "${message}" };
            SimpleConfigurator.ConfigureForTargetLogging(_debugTarget, LogLevel.Info);
        }
 public ManualFlushWrapperTest()
 {
     var loggingConfiguration = new LoggingConfiguration();
     debugTarget = new DebugTarget();
     manualFlushTarget = new ManualFlushWrapper
     {
         WrappedTarget = debugTarget
     };
     loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, manualFlushTarget));
     loggingConfiguration.AddTarget("Manual", manualFlushTarget);
     LogManager.Configuration = loggingConfiguration;
 }
Exemplo n.º 5
0
        public LogBuilderTests()
        {
            var configuration = new LoggingConfiguration();

            var t1 = new LastLogEventListTarget { Name = "t1" };
            var t2 = new DebugTarget { Name = "t2", Layout = "${message}" };
            configuration.AddTarget(t1);
            configuration.AddTarget(t2);
            configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, t1));
            configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, t2));

            LogManager.Configuration = configuration;
        }
Exemplo n.º 6
0
    static void Main(string[] args)
    {
        DebugTarget target = new DebugTarget();
        target.Layout = "${message}";

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Debug("log message");
        logger.Debug("another log message");

        Console.WriteLine("The debug target has been hit {0} times.", target.Counter);
        Console.WriteLine("The last message was '{0}'.", target.LastMessage);
    }
Exemplo n.º 7
0
        public MdlcLayoutRendererTests()
        {
            ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("mdlc", typeof(MdlcLayoutRenderer));

            const string configXml = @"
            <nlog>
                <targets><target name='debug' type='Debug' layout='${mdlc:Item=myitem}${message}' /></targets>
                <rules>
                    <logger name='*' minlevel='Debug' writeTo='debug' />
                </rules>
            </nlog>";

            var element = XElement.Parse(configXml);
            var config = new XmlLoggingConfiguration(element.CreateReader(), null);
            LogManager.Configuration = config;

            _target = LogManager.Configuration.FindTargetByName("debug") as DebugTarget;

            MappedDiagnosticsLogicalContext.Clear();
        }
Exemplo n.º 8
0
        public void Bug4655UnableToReconfigureExistingLoggers()
        {
            var debugTarget1 = new DebugTarget();
            var debugTarget2 = new DebugTarget();

            SimpleConfigurator.ConfigureForTargetLogging(debugTarget1, LogLevel.Debug);

            ILogger logger = LogManager.GetLogger(Guid.NewGuid().ToString("N"));

            logger.Info("foo");

            Assert.Equal(1, debugTarget1.Counter);
            Assert.Equal(0, debugTarget2.Counter);

            LogManager.Configuration.AddTarget("DesktopConsole", debugTarget2);
            LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, debugTarget2));
            LogManager.ReconfigExistingLoggers();

            logger.Info("foo");

            Assert.Equal(2, debugTarget1.Counter);
            Assert.Equal(1, debugTarget2.Counter);
        }
Exemplo n.º 9
0
        public Logging()
        {
            var config = new LoggingConfiguration();
           
            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);
            fileTarget.FileName = "${basedir}/Logs/EligibleLog.log";
            fileTarget.ArchiveEvery = FileArchivePeriod.Day;
            fileTarget.MaxArchiveFiles = 10;
            fileTarget.Footer = "${newline}";
            fileTarget.ConcurrentWrites = true;
            fileTarget.KeepFileOpen = false;
            fileTarget.ArchiveFileName = "${basedir}/Logs/Archives/EligibleLog.{#}.log";
            fileTarget.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence;
            fileTarget.ArchiveDateFormat = "yyyy-MM-dd";
            fileTarget.Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} ${logger} ${level}: ${message}";
            
            var fileRule = new LoggingRule("*", LogLevel.Info, fileTarget);
            config.LoggingRules.Add(fileRule);

            var consoleTarget = new ColoredConsoleTarget();
            config.AddTarget("console", consoleTarget);
            consoleTarget.Footer = "${newline}";
            consoleTarget.Layout = @"${date:format=yyyy-MM-dd HH\:mm\:ss} ${logger} ${level}: ${message}";

            var consoleRule = new LoggingRule("*", LogLevel.Info, consoleTarget);
            config.LoggingRules.Add(consoleRule);

            DebugTarget = new DebugTarget();
            DebugTarget.Layout = @"${message}";

            var debugRule = new LoggingRule("*", LogLevel.Error, DebugTarget);
            config.LoggingRules.Add(debugRule);

            LogManager.Configuration = config;
        }
Exemplo n.º 10
0
        static VariableLayoutRendererTests()
        {
            var t1 = new DebugTarget
            {
                Name = "t1",
                Layout = "${message}|${var:var1:default=x}"
            };

            _mockConfig.AddTarget(t1);
            _mockConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, t1));
            _mockConfig.Variables["var1"] = "my-mocking-manager";
        }