Пример #1
0
        internal void Log(RpcEvent msg)
        {
            var      rpcLog   = msg.Message.RpcLog;
            LogLevel logLevel = (LogLevel)rpcLog.Level;

            if (_executingInvocations.TryGetValue(rpcLog.InvocationId, out ScriptInvocationContext context))
            {
                // Restore the execution context from the original invocation. This allows AsyncLocal state to flow to loggers.
                System.Threading.ExecutionContext.Run(context.AsyncExecutionContext, (s) =>
                {
                    if (rpcLog.Exception != null)
                    {
                        var exception = new Rpc.RpcException(rpcLog.Message, rpcLog.Exception.Message, rpcLog.Exception.StackTrace);
                        context.Logger.Log(logLevel, new EventId(0, rpcLog.EventId), rpcLog.Message, exception, (state, exc) => state);
                    }
                    else
                    {
                        context.Logger.Log(logLevel, new EventId(0, rpcLog.EventId), rpcLog.Message, null, (state, exc) => state);
                    }
                }, null);
            }
            else
            {
                _logger.Log(logLevel, new EventId(0, rpcLog.EventId), rpcLog.Message, null, (state, exc) => state);
            }
        }
        internal void Log(RpcEvent msg)
        {
            // TODO: use scope to attach worker info, map message category if exists

            var      rpcLog   = msg.Message.RpcLog;
            LogLevel logLevel = (LogLevel)rpcLog.Level;

            if (_executingInvocations.TryGetValue(rpcLog.InvocationId, out ScriptInvocationContext context))
            {
                // TODO - remove tracewriter
                // logger.Log(logLevel, new EventId(0, rpcLog.EventId), rpcLog.Message, null, (state, exc) => state);
                TraceEvent trace;
                if (rpcLog.Exception != null)
                {
                    var exception = new Rpc.RpcException(rpcLog.Message, rpcLog.Exception.Message, rpcLog.Exception.StackTrace);

                    // trace = new TraceEvent(logLevel.ToTraceLevel(), rpcLog.Message, rpcLog.Exception.Source, exception);
                    // context.TraceWriter.Trace(trace);
                    context.ResultSource.TrySetException(exception);
                    _executingInvocations.TryRemove(rpcLog.InvocationId, out ScriptInvocationContext _);
                }
                else
                {
                    trace = new TraceEvent(logLevel.ToTraceLevel(), rpcLog.Message);
                    context.TraceWriter.Trace(trace);
                }
            }
            else
            {
                _logger.Log(logLevel, new EventId(0, rpcLog.EventId), rpcLog.Message, null, (state, exc) => state);
            }
        }