internal void SystemLog(GrpcEvent msg) { RpcLog systemLog = msg.Message.RpcLog; LogLevel logLevel = (LogLevel)systemLog.Level; switch (logLevel) { case LogLevel.Warning: _workerChannelLogger.LogWarning(systemLog.Message); break; case LogLevel.Information: _workerChannelLogger.LogInformation(systemLog.Message); break; case LogLevel.Error: { if (systemLog.Exception != null) { Workers.Rpc.RpcException exception = new Workers.Rpc.RpcException(systemLog.Message, systemLog.Exception.Message, systemLog.Exception.StackTrace); _workerChannelLogger.LogError(exception, systemLog.Message); } else { _workerChannelLogger.LogError(systemLog.Message); } } break; default: _workerChannelLogger.LogInformation(systemLog.Message); break; } }
internal void Log(GrpcEvent 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 Workers.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); } }
internal void Log(GrpcEvent 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.LogCategory == RpcLogCategory.CustomMetric) { if (rpcLog.PropertiesMap.TryGetValue(LogConstants.NameKey, out var metricName) && rpcLog.PropertiesMap.TryGetValue(LogConstants.MetricValueKey, out var metricValue)) { // Strip off the name/value entries in the dictionary passed to Log Message and include the rest as the property bag passed to the backing ILogger var rpcLogProperties = rpcLog.PropertiesMap .Where(i => i.Key != LogConstants.NameKey && i.Key != LogConstants.MetricValueKey) .ToDictionary(i => i.Key, i => i.Value.ToObject()); context.Logger.LogMetric(metricName.String, metricValue.Double, rpcLogProperties); } } else { if (rpcLog.Exception != null) { // TODO fix RpcException catch all https://github.com/Azure/azure-functions-dotnet-worker/issues/370 var exception = new Workers.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); } }