Esempio n. 1
0
        private static void SetupLogger()
        {
            var config = new NLog.Config.LoggingConfiguration();

            var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole");
            var layout     = new NLog.Layouts.SimpleLayout(
                "[${date:format=HH\\:mm\\:ss}][${level}]${logger:shortName=true}: ${message}"
                );

            logconsole.Layout   = layout;
            logconsole.Encoding = System.Text.Encoding.UTF8;
            var logfile = new NLog.Targets.FileTarget("logfile");

            logfile.FileName          = "./logs/log.txt";
            logfile.ArchiveFileName   = "log.{#}.txt";
            logfile.ArchiveNumbering  = NLog.Targets.ArchiveNumberingMode.Date;
            logfile.ArchiveDateFormat = "dd-MM-yyyy";
            logfile.ArchiveEvery      = NLog.Targets.FileArchivePeriod.Day;
            logfile.CreateDirs        = true;
            logfile.Layout            = layout;
            logfile.Encoding          = System.Text.Encoding.UTF8;

            config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logconsole, "*");
            config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logfile, "*");

            NLog.LogManager.Configuration = config;
            logger = NLog.LogManager.GetCurrentClassLogger();
        }
Esempio n. 2
0
        /// <inheritdoc/>
        protected override void InitializeLayoutRenderer()
        {
            if (DurationMsFormat == null && string.IsNullOrEmpty(Format) && ReferenceEquals(Culture, CultureInfo.InvariantCulture))
            {
                System.Threading.Interlocked.CompareExchange(ref DurationMsFormat, Enumerable.Range(0, 1000).Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray(), null);
            }

#if !ASP_NET_CORE
            if (!string.IsNullOrEmpty(Format))
            {
                _formatString = "{0:" + Format + "}";
            }
#elif ASP_NET_CORE2
            if (string.IsNullOrEmpty(Format) && ReferenceEquals(Culture, CultureInfo.InvariantCulture))
            {
                _scopeTiming = new NLog.Layouts.SimpleLayout("${scopetiming}");
            }
            else if (ReferenceEquals(Culture, CultureInfo.InvariantCulture))
            {
                _scopeTiming = new NLog.Layouts.SimpleLayout($"${{scopetiming:Format={Format}}}");
            }
            else
            {
                _scopeTiming = new NLog.Layouts.SimpleLayout($"${{scopetiming:Format={Format}:Culture={Culture}}}");
            }
#endif

            base.InitializeLayoutRenderer();
        }
Esempio n. 3
0
        public override Config_Logging ReadJson(JsonReader reader, Type objectType, Config_Logging existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            Config_Logging output = Config_Logging.Defaults;

            var data = JObject.Load(reader);

            if (data["Level"] is JToken logLevel)
            {
                var value = logLevel.Value <string>();
                output.LogLevel = LogLevel.FromString(value);
            }

            if (data["WebService"] is JToken webService)
            {
                var parameters = webService["parameters"]?.ToObject <Dictionary <string, string> >() ?? new Dictionary <string, string>();
                webService.OfType <JProperty>().Where(x => x.Name == "parameters").ToList().ForEach(x => x.Remove());

                var value = webService.ToObject <WebServiceTarget>();
                foreach (var param in parameters)
                {
                    var layout = new NLog.Layouts.SimpleLayout(param.Value);
                    value.Parameters.Add(new MethodCallParameter(param.Key, layout));
                }
                output.WebService = value;
            }

            if (data["RetryingWrapper"] is JToken retryWrapper)
            {
                var value = retryWrapper.ToObject <RetryingTargetWrapper>();
                output.RetryingWrapper = value;
            }

            return(output);
        }
Esempio n. 4
0
        private static void ConfigureLogging()
        {
            var layout = new NLog.Layouts.SimpleLayout("${longdate}:${message}");
            var target = new ConsoleTarget {
                Layout = layout, Name = MigratorLogManager.LOGGER_NAME
            };

            MigratorLogManager.SetNLogTarget(target);
        }
Esempio n. 5
0
        private void ConfigureLogging()
        {
            var simpleLayout = new NLog.Layouts.SimpleLayout("${longdate}:${message}");
            var nlogTarget   = new NAntNLogTarget(this)
            {
                Layout = simpleLayout, Name = MigratorLogManager.LOGGER_NAME
            };

            MigratorLogManager.SetNLogTarget(nlogTarget);
        }
Esempio n. 6
0
        private static void ColoredConsoleTarget(LoggingConfiguration config, NLog.LogLevel loglevel, string name)
        {
            var layout = new NLog.Layouts.SimpleLayout("${longdate}|${level:uppercase=true}|${logger}|${callsite:className=true:fileName=false:includeSourcePath=false:methodName=true}|${message}");

            var target = new ColoredConsoleTarget(name)
            {
                Layout = layout
            };

            config.AddTarget(target);
            config.LoggingRules.Add(new LoggingRule(name, loglevel, target));
        }
Esempio n. 7
0
        private static void SetupLogger()
        {
            var config = new NLog.Config.LoggingConfiguration();

            var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole");
            var layout     = new NLog.Layouts.SimpleLayout(
                "[${date:format=HH\\:mm\\:ss}][${level}]${logger:shortName=true}: ${message}"
                );

            logconsole.Layout   = layout;
            logconsole.Encoding = System.Text.Encoding.UTF8;

            config.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logconsole, "*");

            NLog.LogManager.Configuration = config;
            logger = NLog.LogManager.GetCurrentClassLogger();
        }
Esempio n. 8
0
        private static void CreateLogFileTarget(LoggingConfiguration config, NLog.LogLevel loglevel, string dirpath, string name, string filename, int days)
        {
            var layout = new NLog.Layouts.SimpleLayout("${longdate}|${level:uppercase=true}|${logger}|${callsite:className=true:fileName=false:includeSourcePath=false:methodName=true}|${message}");

            var target = new FileTarget(name)
            {
                FileNameKind     = FilePathKind.Absolute,
                ArchiveEvery     = FileArchivePeriod.Day,
                MaxArchiveFiles  = days,
                ArchiveNumbering = ArchiveNumberingMode.Date,
                EnableFileDelete = true,
                FileName         = Path.Combine(dirpath, filename + @".txt"),
                Layout           = layout
            };

            config.AddTarget(target);
            config.LoggingRules.Add(new LoggingRule(name, loglevel, target));
        }
Esempio n. 9
0
 private void ConfigureLogging()
 {
     var layout = new NLog.Layouts.SimpleLayout("${longdate}:${message}");
     var target = new MsBuildNLogTarget(Log) { Layout = layout, Name = MigratorLogManager.LOGGER_NAME };
     MigratorLogManager.SetNLogTarget(target);
 }
Esempio n. 10
0
 private void ConfigureLogging()
 {
     var simpleLayout = new NLog.Layouts.SimpleLayout("${longdate}:${message}");
     var nlogTarget = new NAntNLogTarget(this) { Layout = simpleLayout, Name = MigratorLogManager.LOGGER_NAME };
     MigratorLogManager.SetNLogTarget(nlogTarget);
 }