Ejemplo n.º 1
0
    public async Task <LogGrpcResponse> AddLogsAsync(LogGrpcRequest request, CallContext context = default)
    {
        var response = new LogGrpcResponse();

        try
        {
            foreach (var log in request.Logs)
            {
                log.LoggerName = request.Logger;
                _laobianLogQueue.Add(log);
            }
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, $"{nameof(LogGrpcService)}({nameof(AddLogsAsync)}) failed.");
            response.IsOk    = false;
            response.Message = ex.Message;
        }

        return(await Task.FromResult(response));
    }
Ejemplo n.º 2
0
    public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
                             Func <TState, Exception, string> formatter)
    {
        if (!IsEnabled(logLevel))
        {
            return;
        }

        try
        {
            var log = GetScopeInfo();
            log.Message   = formatter(state, exception);
            log.Exception = exception?.ToString();
            log.Level     = logLevel;
            log.TimeStamp = DateTime.Now;
            _logQueue.Add(log);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }