Exemplo n.º 1
0
 protected override void Write(AsyncLogEventInfo[] logEvents)
 {
     try {
         foreach (var lev in logEvents)
         {
             lev.Continuation(null);
         }
         connector.SendLogRecords(logEvents.Select(lev => ConvertLogEventToLogRecord(lev.LogEvent)));
     } catch (StackOverflowException) {
         throw;
     } catch (ThreadAbortException) {
         throw;
     } catch (OutOfMemoryException) {
         throw;
     } catch (Exception ex) {
         // swallow all other exceptions
         Trace.TraceError("Exception occured while trying to send a log records batch: {0}", ex);
     }
 }
Exemplo n.º 2
0
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            var logrecs = loggingEvents.Select(ConvertLogEventToLogRecord);

            connector.SendLogRecords(logrecs);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            int numberOfLogs = 10000;
            int batchSize    = 0;

            var p = new OptionSet {
                { "n|nlogs=", "number of logs to generate", v => numberOfLogs = Int32.Parse(v) },
                { "b|batchsize=", "send logs in batches", v => batchSize = Int32.Parse(v) },
            };

            List <String> extra;

            try {
                extra = p.Parse(args);
            } catch (Exception ex) {
                Console.Write("testlog: ");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Try `testlog --help' for more information.");
                return;
            }

            if (extra.Count == 0)
            {
                Console.WriteLine("ERROR: Missing diagnostics url.");
                Console.WriteLine();
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            int  errorsCnt        = 0;
            int  recordsGenerated = 0;
            long ticks            = 0;

            using (new Timer((o) => { Console.Write("\rProcessed: {0} / {1}               ", recordsGenerated, numberOfLogs); }, null, 0, 500)) {
                var sw = new Stopwatch();
                sw.Start();
                using (var connector = new HttpCastleConnector(new Uri(extra[0]))) {
                    var opt = new ParallelOptions {
                        MaxDegreeOfParallelism = Environment.ProcessorCount
                    };
                    if (batchSize > 0)
                    {
                        Parallel.For(0, numberOfLogs / batchSize, opt, (i) => {
                            var recs = new LogRecord[batchSize];
                            for (int j = 0; j < batchSize; j++)
                            {
                                recs[j] = GenerateRandomLogRecord();
                            }
                            try {
                                connector.SendLogRecords(recs);

                                Interlocked.Add(ref ticks, sw.Elapsed.Ticks);
                                Interlocked.Add(ref recordsGenerated, batchSize);
                            } catch (Exception ex) {
                                Interlocked.Increment(ref errorsCnt);
                                Console.WriteLine("Error occured: {0} - {1}", ex.GetType().FullName, ex.Message);
                            }
                        });
                    }
                    else
                    {
                        Parallel.For(0, numberOfLogs, opt, (i) => {
                            try {
                                connector.SendLogRecord(GenerateRandomLogRecord());

                                Interlocked.Increment(ref recordsGenerated);
                            } catch (Exception ex) {
                                Interlocked.Increment(ref errorsCnt);
                                Console.WriteLine("Error occured: {0} - {1}", ex.GetType().FullName, ex.Message);
                            }
                        });
                    }
                }
                sw.Stop();

                var ts = sw.Elapsed;
                Console.WriteLine("\rRecords generated: {0}, errors: {1}, time: {2:#,#.##} ms which gives {3:0.000} processed records / sec", recordsGenerated,
                                  errorsCnt, ts.TotalMilliseconds, recordsGenerated / ts.TotalSeconds);
            }
        }