Ejemplo n.º 1
0
        public void Log(LogLevel logLevel, string message, Exception exception = null, bool isUserLog = false)
        {
            var log = $"{logLevel}: {message}";

            Console.WriteLine(log);
            FullLog.Add(log);
        }
        public async void Log(LogLevel logLevel, string message, Exception exception = null, bool isUserLog = false)
        {
            var invocationId = _invocationId ?? "N/A";

            if (isUserLog)
            {
                // For user logs, we send them over Rpc with details about the invocation.
                var logMessage = new StreamingMessage
                {
                    RequestId = _requestId,
                    RpcLog    = new RpcLog()
                    {
                        Exception    = exception?.ToRpcException(),
                        InvocationId = invocationId,
                        Level        = logLevel,
                        Message      = message
                    }
                };

                await _msgStream.WriteAsync(logMessage);
            }
            else
            {
                // For system logs, we log to stdio with a prefix of LanguageWorkerConsoleLog.
                // These are picked up by the Functions Host
                Console.WriteLine($"{SystemLogPrefix}Request Id: {_requestId}\nInvocation Id: {_invocationId}\nLog Message:\n{message}\n");
            }
        }
Ejemplo n.º 3
0
 private void VerifyMessageLogged(LogLevel expectedLogLevel, string expectedMessage, bool expectedIsUserLog)
 {
     _mockLogger.Verify(
         _ => _.Log(
             expectedIsUserLog,
             expectedLogLevel,
             It.Is <string>(message => message.Contains(expectedMessage)),
             It.IsAny <Exception>()));
 }
        private static void WriteSystemLog(LogLevel logLevel, string message, string requestId, string invocationId)
        {
            // For system logs, we log to stdio with a prefix of LanguageWorkerConsoleLog.
            // These are picked up by the Functions Host
            var stringBuilder = new StringBuilder(SystemLogPrefix);

            stringBuilder.Append("System Log: {");
            if (!string.IsNullOrEmpty(requestId))
            {
                stringBuilder.Append($" Request-Id: {requestId};");
            }
            if (!string.IsNullOrEmpty(invocationId))
            {
                stringBuilder.Append($" Invocation-Id: {invocationId};");
            }
            stringBuilder.Append($" Log-Level: {logLevel};");
            stringBuilder.Append($" Log-Message: {message}");
            stringBuilder.AppendLine(" }");

            Console.WriteLine(stringBuilder.ToString());
        }
Ejemplo n.º 5
0
        public void Log(LogLevel logLevel, string message, Exception exception = null, bool isUserLog = false)
        {
            if (isUserLog)
            {
                // For user logs, we send them over Rpc with details about the invocation.
                var logMessage = new StreamingMessage
                {
                    RequestId = _requestId,
                    RpcLog    = new RpcLog()
                    {
                        Exception    = exception?.ToRpcException(),
                        InvocationId = _invocationId ?? "N/A",
                        Level        = logLevel,
                        Message      = message
                    }
                };

                _msgStream.Write(logMessage);
            }
            else
            {
                // For system logs, we log to stdio with a prefix of LanguageWorkerConsoleLog.
                // These are picked up by the Functions Host
                _systemLogMsg.Append(SystemLogPrefix).AppendLine("System Log: {");
                if (!string.IsNullOrEmpty(_requestId))
                {
                    _systemLogMsg.AppendLine($"  Request-Id: {_requestId}");
                }
                if (!string.IsNullOrEmpty(_invocationId))
                {
                    _systemLogMsg.AppendLine($"  Invocation-Id: {_invocationId}");
                }
                _systemLogMsg.AppendLine($"  Log-Message: {message}").AppendLine("}");

                Console.WriteLine(_systemLogMsg.ToString());
                _systemLogMsg.Clear();
            }
        }
Ejemplo n.º 6
0
        public void Log(LogLevel logLevel, string message, Exception exception = null, bool isUserLog = false)
        {
            if (isUserLog)
            {
                // For user logs, we send them over Rpc with details about the invocation.
                var logMessage = new StreamingMessage
                {
                    RequestId = _requestId,
                    RpcLog    = new RpcLog()
                    {
                        Exception    = exception?.ToRpcException(),
                        InvocationId = _invocationId ?? "N/A",
                        Level        = logLevel,
                        Message      = message
                    }
                };

                _msgStream.Write(logMessage);
            }
            else
            {
                WriteSystemLog(message, _systemLogMsg, _requestId, _invocationId);
            }
        }
 internal static void WriteSystemLog(LogLevel logLevel, string message)
 {
     WriteSystemLog(logLevel, message, requestId: null, invocationId: null);
 }
 public abstract void Log(LogLevel logLevel, string message, Exception exception = null, bool isUserLog = false);