コード例 #1
0
        static async Task Run(string server, string apiKey, string file, IDictionary <string, string> additionalTags, ulong bodyLimitBytes, ulong payloadLimitBytes)
        {
            var originalFilename = Path.GetFileName(file);

            Log.Information("Opening JSON log file {OriginalFilename}", originalFilename);

            var importId = Guid.NewGuid();
            var tags     = new Dictionary <string, object>
            {
                ["ImportId"] = importId
            };

            if (additionalTags?.Any() ?? false)
            {
                Log.Information("Adding tags {@Tags} to import", additionalTags);

                foreach (var p in additionalTags)
                {
                    tags.Add(p.Key, p.Value);
                }
            }

            var lazyReader = JsonFileReader.LazyRead(file, tags);
            var logBuffer  = new BufferedLogReader(lazyReader);

            var shipper = new HttpImporter(logBuffer, new SeqImportConfig
            {
                ServerUrl            = server,
                ApiKey               = apiKey,
                EventBodyLimitBytes  = bodyLimitBytes,
                RawPayloadLimitBytes = payloadLimitBytes
            });

            var sw = Stopwatch.StartNew();

            Log.Information("Starting import {ImportId}", importId);
            await shipper.Import();

            sw.Stop();
            Log.Information("Import {ImportId} completed in {Elapsed:0.0} ms", importId, sw.Elapsed.TotalMilliseconds);
        }