Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            NLogUtils.CreateConfigFileIfNotExists();

            SimpleLayout simpleLayout;

            LogLayout = LogManager.Configuration.Variables.TryGetValue("TextBoxLayout", out simpleLayout)
                ? simpleLayout.Text
                : "${date:format=HH\\:MM\\:ss.ffff} [${level:upperCase=true}]\t[${logger:shortName=true}] ${message}";

            MinLogLevel = LogManager.Configuration.Variables.TryGetValue("MinLogLevel", out simpleLayout)
                ? LogLevel.FromString(simpleLayout.Text)
                : LogLevel.Info;

            if (
                args.Any(
                    x =>
                    string.Equals(x, "/v", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(x, "/verbose", StringComparison.OrdinalIgnoreCase)))
            {
                MinLogLevel = LogLevel.Debug;
                EnabledDebugForAllRules();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ServerApplicationContext());
        }
Ejemplo n.º 2
0
        private static void InitializeLogger()
        {
            NLogUtils.CreateConfigFileIfNotExists();

            SimpleLayout simpleLayout;
            var          layout = LogManager.Configuration.Variables.TryGetValue("TextBoxLayout", out simpleLayout)
                ? simpleLayout.Text
                : "${date:format=HH\\:MM\\:ss.ffff} [${level:upperCase=true}]\t[${logger:shortName=true}] ${message}";

            var minLogLevel = LogManager.Configuration.Variables.TryGetValue("MinLogLevel", out simpleLayout)
                ? LogLevel.FromString(simpleLayout.Text)
                : LogLevel.Info;

            var reconfigLoggers = false;

            var fileTarget = LogManager.Configuration.FindTargetByName <FileTarget>("file");

            if (fileTarget != null && LogManager.Configuration.Variables.TryGetValue("VerboseLayout", out simpleLayout))
            {
                simpleLayout.Text = simpleLayout.Text.Replace("${callsite", "${callsite:skipFrames=3");
                fileTarget.Layout = simpleLayout;
                reconfigLoggers   = true;
            }

            var target = new ColoredConsoleTarget {
                Layout = layout, Name = "console"
            };

            LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", minLogLevel, target));

            LogManager.Configuration.Reload(); //important, refreshes the config

            if (reconfigLoggers)
            {
                LogManager.ReconfigExistingLoggers();
            }
        }