c# - 将 C# Console.Write* 与 AWS Lambda 结合使用

标签 c# amazon-web-services lambda

问这样一个基本问题我觉得自己像个白痴,但这里……我第一次在 C# 中尝试 AWS Lambda,并根据文档:

Anything written to standard out or standard error - using Console.Write or a similar method - will be logged in CloudWatch Logs.

好的,执行后我得到以下运行时异常:

Unable to load DLL 'api-ms-win-core-processenvironment-l1-1-0.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E): DllNotFoundException
at Interop.mincore.GetStdHandle(Int32 nStdHandle)
at System.ConsolePal.GetStandardFile(Int32 handleType, FileAccess access)
at System.Console.<>c.<get_Out>b__25_0()
at System.Console.EnsureInitialized[T](T& field, Func`1 initializer)
at System.Console.WriteLine(String value)

我的问题是,我应该如何/在哪里添加它要求的引用?答案似乎并不明显。

最佳答案

作为 Console.WriteConsole.WriteLine 的替代方法,您可以在静态 Amazon 上使用 Log 方法。 Lambda.Core.LambdaLogger 类。

private void DoSomething() {
    LambdaLogger.Log("Log message");
}

可以在此处找到更多信息:http://docs.aws.amazon.com/lambda/latest/dg/dotnet-logging.html

关于c# - 将 C# Console.Write* 与 AWS Lambda 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42183485/

相关文章:

c# - 取决于 viewmodel 定义的按钮数量的对话框窗口

amazon-web-services - 如何引用 CloudFormationProvisionedProduct 输出

amazon-web-services - 如何在 API 网关中上传大于 5mb 的大文件?使用无服务器和 nodejs

amazon-web-services - 在AWS S3中部署react-redux应用程序

c# - 在 C# 中实现部分递归函数

c# - 我如何在 c# 中格式化 07/03/2012 到 2012 年 3 月 7 日

c# - 避免在后台任务仍在运行时处理DbContext的更优雅的解决方案

c++ - 为什么可以使用 [=] 来修改 lambda 中的成员变量?

c# - 根据满足的较低级别标准获取顶级实体

c# - 用 lambda 表达式替换委托(delegate)