コード例 #1
0
        private void Process(FileInfo file, long offset, long length)
        {
            using (var f = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))

            {
                var b = new byte[length - offset];
                f.Read(b, (int)offset, (int)(b.Length));
                using (var ms = new MemoryStream(b))
                    using (var t = XmlReader.Create(ms, new XmlReaderSettings()
                    {
                    }))
                    {
                        var le = ParseLog4NetXmlLogEvent(t, "eds");
                        if (le != null)
                        {
                            _logProcessor.ProcessLog(le);
                        }
                    }
            }
        }
コード例 #2
0
        public override void OnEnd(LogRecord data)
        {
            var level = 0;

            switch (data.LogLevel)
            {
            case LogLevel.Critical:
                level = 21;
                break;

            case LogLevel.Debug:
                level = 5;
                break;

            case LogLevel.Error:
                level = 17;
                break;

            case LogLevel.Information:
                level = 9;
                break;

            case LogLevel.Trace:
                level = 1;
                break;

            case LogLevel.Warning:
                level = 13;
                break;
            }

            var attributes = new Dictionary <string, object>();
            var message    = _enricher.Enrich(attributes, data.FormattedMessage, data.State ?? data.StateValues, data.Exception, attr =>
            {
                data.ForEachScope((scope, a) =>
                {
                    foreach (var kvp in scope)
                    {
                        a[kvp.Key] = kvp.Value;
                    }
                }, attr);
            });

            _processor.ProcessLog(level, data.Timestamp, message, attributes, data.SpanId.ToString(), data.TraceId.ToString());
        }
コード例 #3
0
ファイル: LogTcpReceiver.cs プロジェクト: davidnajar/logR
        private async Task InitSocket()
        {
            while (!_cancellationToken.IsCancellationRequested)
            {
                Socket clientSocket = null;
                try
                {
                    clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    await clientSocket.ConnectAsync(_settings.Server, _settings.Port);

                    do
                    {
                        byte[]        array  = new byte[8192];
                        Memory <byte> memory = new Memory <byte>(array);
                        await clientSocket.ReceiveAsync(memory, SocketFlags.None, _cancellationToken);

                        ArraySegment <byte> segment = default;
                        bool leased = false;
                        try
                        {
                            if (!MemoryMarshal.TryGetArray <byte>(memory, out segment))
                            {
                                var arr = ArrayPool <byte> .Shared.Rent(memory.Length);

                                memory.CopyTo(arr);
                                segment = new ArraySegment <byte>(arr, 0, memory.Length);
                                leased  = true;
                            }
                            using (var ms = new MemoryStream(segment.Array, segment.Offset, segment.Count))
                            {
                                var settings = new XmlReaderSettings();
                                settings.Schemas.Add(xsd);
                                settings.ValidationType = ValidationType.None;
                                using (var xmlReader = XmlReader.Create(ms, _xmlReaderSettings, _context))
                                {
                                    var le = ParseLog4NetXmlLogEvent(xmlReader, "eds");
                                    if (le != null)
                                    {
                                        foreach (var log in le)
                                        {
                                            await _logProcessor.ProcessLog(log);
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (leased)
                            {
                                ArrayPool <byte> .Shared.Return(segment.Array);
                            }
                        }
                    } while (!_cancellationToken.IsCancellationRequested);
                }
                catch (Exception ex)
                {
                    clientSocket?.Dispose();
                    //reconnect
                }
            }
        }
コード例 #4
0
ファイル: LogPacketHandler.cs プロジェクト: davidnajar/logR
 public override async Task Process(LogEvent packet, IPacketContext context)
 {
     await _logProcessor.ProcessLog(packet);
 }
コード例 #5
0
 public void PutLog(LogEvent ect)
 {
     _logProcessor.ProcessLog(ect);
 }