Esempio n. 1
0
        private static void Main(string[] args)
        {
            IList <LogLevel> logs =
                Enumerable.Range(0, 1000).Select(i => LogLevel.Trace)
                .Concat(Enumerable.Range(0, 500).Select(i => LogLevel.Debug))
                .Concat(Enumerable.Range(0, 300).Select(i => LogLevel.Info))
                .Concat(Enumerable.Range(0, 100).Select(i => LogLevel.Warn))
                .Concat(Enumerable.Range(0, 50).Select(i => LogLevel.Error))
                .Concat(Enumerable.Range(0, 30).Select(i => LogLevel.Error))
                .ToList();

            var apps    = new[] { "vp", "db", "ca", "sms", "email" };
            var modules = new[] { "auth", "parse", "fetch", "load", "upload", "ocr" };

            var data = messages.Concat(text.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries))
                       .Select(i => i.Trim()).ToArray();

            for (;;)
            {
                for (int i = 0; i < modules.Length; i++)
                {
                    for (int j = 0; j < apps.Length; j++)
                    {
                        for (int k = 0; k < logs.Count; k++)
                        {
                            var module = modules[rnd.Next(0, modules.Length)];
                            var app    = apps[rnd.Next(0, apps.Length)];
                            var lvl    = logs[rnd.Next(0, logs.Count)];

                            nlog.Setup("yourid", app, module)
                            .Log(lvl, data[rnd.Next(0, data.Length)])
                            .WithTags(Guid.NewGuid())
                            .WithTags(app + module, Guid.NewGuid().ToString("N"))
                            .WithField("timeout", 0.3)
                            .WithFields(new Dictionary <string, object> {
                                { "cpu", rnd.NextDouble() },
                                { "mem", rnd.Next(256, 1025) },
                                { "text", data[rnd.Next(0, data.Length)] },
                                { "pc", Environment.MachineName },
                                { "ams", "NLog.LumberjackTarget" },
                                { "tmp", Path.GetTempPath() },
                                { "os", Environment.OSVersion.ToString() },
                                { "cpucnt", Environment.ProcessorCount },
                                { "domain", Environment.UserDomainName },
                                { "version", Environment.Version },
                                { "stacktrace", Environment.StackTrace },
                            })
                            //.Alert("myrule", "event raised!")
                            //.Measure("auth", 100)
                            .Commit();
                        }
                        Thread.Sleep(50000);
                    }
                    Thread.Sleep(10000);
                }
            }
        }