Exemplo n.º 1
0
        private void FlushLogs()
        {
            var logs = _logShipping.GetAndFlushLogs();

            foreach (var l in logs)
            {
                switch (l.LogLevel)
                {
                case ConsoleLogLevel.Debug:
                    _consoleHandle.LogDebug(l.Message);
                    break;

                case ConsoleLogLevel.Info:
                    _consoleHandle.LogInfo(l.Message);
                    break;

                case ConsoleLogLevel.Warning:
                    _consoleHandle.LogWarning(l.Message);
                    break;

                case ConsoleLogLevel.Error:
                    _consoleHandle.LogError(l.Message);
                    break;
                }
            }
        }
        public async Task RunLogShipping()
        {
            while (true)
            {
                await Task.Yield();

                if (!_remoteClient.IsConnected)
                {
                    continue;
                }

                var outbound = _remoteClient.TryObtainOutboundReaderWriter();
                if (outbound == null)
                {
                    continue;
                }
                try
                {
                    var logs = _logShipping.GetAndFlushLogs();
                    outbound.Writer.Write("logs");
                    outbound.Writer.Write((Int32)logs.Length);
                    for (var i = 0; i < logs.Length; i++)
                    {
                        outbound.Writer.Write((Int32)logs[i].LogLevel);
                        outbound.Writer.Write(logs[i].Message);
                    }
                    outbound.Writer.Flush();
                }
                finally
                {
                    _remoteClient.ReleaseOutboundReaderWriter();
                }
            }
        }