上下文 当函数计算运行您的函数时,会将上下文对象传递到执行方法中。该对象包含有关调用、服务、函数和执行环境等信息。 上下文接口 您可以通过ICfContext接口获取上下文相关信息,接口定义如下: 字段 说明 string RequestId 调用请求ID。 ICfFunctionParameter FunctionParam 函数相关参数信息。 ICfLogger Logger 日志对象。 string AccountId 用户的AccountId。 string Region 当前函数所在的Region。 示例:通过上下文接口获取请求ID csharp using System; using System.IO; using System.Text; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Serverless.Cf; namespace Example { public class Hello { public async Task Handler(Stream input, ICfContext context) { var str "Hello world, requestId is: " + context.RequestId; byte[] bytetxt Encoding.UTF8.GetBytes(str); MemoryStream output new MemoryStream(); output.Write(bytetxt, 0, bytetxt.Length); return output; } static void Main(string[] args) { } } }