Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C# Console.Write* with AWS Lambda

I feel like an idiot for asking such a basic question but here goes... I'm trying out AWS Lambda in C# for the first time and according to the docs:

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

OK well upon execution I get the following runtime exception:

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)

My question is, how / where am I supposed to add the reference it's asking for? The answer seems non obvious.

like image 746
ThatCreole Avatar asked Oct 22 '25 01:10

ThatCreole


1 Answers

As an alternative to Console.Write or Console.WriteLine, you can use the Log method on the static Amazon.Lambda.Core.LambdaLogger class.

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

Some more info can be found here: http://docs.aws.amazon.com/lambda/latest/dg/dotnet-logging.html

like image 145
JustSomeQuickGuy Avatar answered Oct 23 '25 14:10

JustSomeQuickGuy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!