コード例 #1
0
ファイル: LogUtil.cs プロジェクト: morz/OETS.Journal
		/// <summary>
		/// Will enable logging to the console
		/// </summary>
		public static void SetupConsoleLogging()
		{
			var config = LogManager.Configuration ?? new LoggingConfiguration();

			var consoleTarget = new ColoredConsoleTarget
			{
				Layout = "${processtime} [${level}] ${message} ${exception:format=tostring}"
			};
			config.AddTarget("console", consoleTarget);

			config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));

			LogManager.Configuration = config;
			LogManager.EnableLogging();
		}
コード例 #2
0
ファイル: Example.cs プロジェクト: tdhieu/openvss
    static void Main(string[] args)
    {
        ColoredConsoleTarget target = new ColoredConsoleTarget();
        target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

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

        Logger logger = LogManager.GetLogger("Example");
        logger.Trace("trace log message");
        logger.Debug("debug log message");
        logger.Info("info log message");
        logger.Warn("warn log message");
        logger.Error("error log message");
        logger.Fatal("fatal log message");
    }
コード例 #3
0
ファイル: Example.cs プロジェクト: CharlieBP/NLog
    static void Main(string[] args)
    {
        ColoredConsoleTarget target = new ColoredConsoleTarget();
        target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
        target.RowHighlightingRules.Add(
                new ConsoleRowHighlightingRule(
                    "level >= LogLevel.Error and contains(message,'serious')", // condition
                    ConsoleOutputColor.White, // foreground color
                    ConsoleOutputColor.Red // background color
                    )
                );

        target.RowHighlightingRules.Add(
                new ConsoleRowHighlightingRule(
                    "starts-with(logger,'Example')", // condition
                    ConsoleOutputColor.Yellow, // foreground color
                    ConsoleOutputColor.DarkBlue) // background color
                );
        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);

        // LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("ColoredConsoleTargetRowHighlighting.nlog");

        Logger logger = LogManager.GetLogger("Example");
        logger.Trace("trace log message");
        logger.Debug("debug log message");
        logger.Info("info log message");
        logger.Warn("warn log message");
        logger.Error("very serious error log message");
        logger.Fatal("fatal log message, rather serious");

        Logger logger2 = LogManager.GetLogger("Another");
        logger2.Trace("trace log message");
        logger2.Debug("debug log message");
        logger2.Info("info log message");
        logger2.Warn("warn log message");
        logger2.Error("very serious error log message");
        logger2.Fatal("fatal log message");
    }
コード例 #4
0
ファイル: Example.cs プロジェクト: CharlieBP/NLog
    static void Main(string[] args)
    {
        ColoredConsoleTarget target = new ColoredConsoleTarget();
        target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
        target.WordHighlightingRules.Add(
                new ConsoleWordHighlightingRule("log", 
                    ConsoleOutputColor.NoChange, 
                    ConsoleOutputColor.DarkGreen));
        target.WordHighlightingRules.Add(
                new ConsoleWordHighlightingRule("abc", 
                    ConsoleOutputColor.Cyan, 
                    ConsoleOutputColor.NoChange));
                

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

        Logger logger = LogManager.GetLogger("Example");
        logger.Trace("trace log message abcdefghijklmnopq");
        logger.Debug("debug log message");
        logger.Info("info log message abc abcdefghijklmnopq");
        logger.Warn("warn log message");
        logger.Error("error log abcdefghijklmnopq message abc");
        logger.Fatal("fatal log message abcdefghijklmnopq abc");
    }
コード例 #5
0
 private static Logger CreateLogging()
 {
     var config = new LoggingConfiguration();
     var target = new ColoredConsoleTarget() {Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"};
     config.AddTarget("console", target);
     config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, target));
     LogManager.Configuration = config;
     return LogManager.GetCurrentClassLogger();
 }