Ritu

Ritu

  • 1.4k
  • 348
  • 43.5k

Write logs in AWS Log

Jun 22 2023 10:12 AM

Hi

I want to write logs in AWS cloudwatch using lambda
I'm using ILambdalogger but getting error in logs

 

public string FunctionHandler(string input, ILambdaContext context)
    {
        var logger = context.Logger;
        sendLog(logger);       

        return input.ToUpper();
    }

    public static void sendLog(ILambdaLogger lambdaLogger)
    {
        resultToFile.errors = new List<ErrorModel>();
        resultToFile.errors.Add(new ErrorModel
        {
            CrDatTime = CommonHelper.ConvertDateTime_UTCtoEST(),
            LogLevel = LogLevel.Information.ToString(),
            MsgDetails = "1. AWS FunctionHandler Initialized",
            SourceMethodName = "FunctionHandler"
        });      

        if (resultToFile.errors != null)
        {
            lambdaLogger.LogInformation("Data executed successfully");
        }
        else
        {
            lambdaLogger.LogError("Error");
        }
    }

 

Please help.


Answers (2)