public void NLogLoggerTestWithConfig()
        {
            var config = new LoggingConfiguration();

            Nlog.Init(config);

            var logger      = LogManager.GetLogger(typeof(LoggingTests));
            var loggerScope = LogManager.GetLogger("TestScope");

            CallLogger(logger);
            CallLogger(loggerScope);
        }
        public void NLogLoggerTestWithConfigAllLogLevelsEnabled()
        {
            var config = new LoggingConfiguration();

            config.AddTarget("null", new NullTarget());
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, "null");
            Nlog.Init(config);

            var logger      = LogManager.GetLogger(typeof(LoggingTests));
            var loggerScope = LogManager.GetLogger("TestScope");

            CallLogger(logger);
            CallLogger(loggerScope);
        }
        public void NLogLoggerTest()
        {
            Nlog.Init();
            var logger      = LogManager.GetLogger(typeof(LoggingTests));
            var loggerScope = LogManager.GetLogger("TestScope");

            Assert.True(logger.IsDebugEnabled);
            Assert.True(logger.IsErrorEnabled);
            Assert.True(logger.IsFatalEnabled);
            Assert.True(logger.IsInfoEnabled);
            Assert.True(logger.IsTraceEnabled);
            Assert.True(logger.IsWarnEnabled);

            CallLogger(logger);
            CallLogger(loggerScope);
        }
Beispiel #4
0
        public static void InitNlog(string logPath)
        {
            var configPath = FileSys.Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ?? Env.CurrentDirectory;

            if (string.IsNullOrWhiteSpace(configPath))
            {
                configPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            }
            var nlogConfigFile = FileSys.Path.Combine(configPath, "NLog.config");

            if (!FileSys.File.Exists(nlogConfigFile))
            {
                throw new ApplicationException("NLog.config not found");
            }
            Nlog.Init(nlogConfigFile);
            NLog.LogManager.Configuration.Variables["LogPath"] = logPath;
        }