Exemple #1
0
        private async Task AddLog(string errorMessage, DateTime occurTime)
        {
            TcpDuplexListenerLog log = new TcpDuplexListenerLog()
            {
                IsError         = true,
                ErrorMessage    = errorMessage,
                ExecuteDuration = 0,
                ListenerName    = _listener.Name,
                RequestContent  = string.Empty,
                RequestTime     = occurTime,
                ResponseContent = string.Empty,
                ResponseTime    = DateTime.UtcNow
            };
            var t = Task.Run(async() =>
            {
                try
                {
                    await log.Add();
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogError(LogCategoryName, $"TcpDuplexListener {_listener.Name}, AddLog Error,message:{ex.Message},stack:{ex.StackTrace}");
                }
            });

            await Task.FromResult(0);
        }
Exemple #2
0
        private async Task AddLog(TcpDuplexAcceptContext token)
        {
            TcpDuplexListenerLog log = new TcpDuplexListenerLog()
            {
                IsError         = !token.ExecuteSuccess,
                ErrorMessage    = token.ExecuteError ?? string.Empty,
                ExecuteDuration = (int)token.Watch.ElapsedMilliseconds,
                ListenerName    = _listener.Name,
                RequestContent  = UTF8Encoding.UTF8.GetString(token.RequestData.ToArray()),
                RequestTime     = token.RequestDateTime,
                ResponseContent = token.ResponseBytes == null ? string.Empty : UTF8Encoding.UTF8.GetString(token.ResponseBytes.ToArray()),
                ResponseTime    = DateTime.UtcNow
            };
            var t = Task.Run(async() =>
            {
                try
                {
                    await log.Add();
                }
                catch (Exception ex)
                {
                    LoggerHelper.LogError(LogCategoryName, $"TcpDuplexListener {_listener.Name}, AddLog Error,message:{ex.Message},stack:{ex.StackTrace}");
                }
            });

            await Task.FromResult(0);
        }