title: Serilog CloudWatchSink not working from Lambda Function
body: <p>I have a .NET Core 2 WebAPI application, running in AWS Lambda.   I am using the Serilog AwsCloudWatch sink.  I have also implemented middleware from the Datalust <a href="https://github.com/datalust/serilog-middleware-example" rel="nofollow noreferrer">SerilogMiddleware example</a>.</p>
  
  <p>This all works perfectly from my development environment (logs are written to the correct CloudWatch Log Group).   However, when the application runs in Lambda, no logging occurs.  I have enabled Serilog SelfLog however there are no errors logged, so I don't believe it's an AWS credentials issue.</p>
  
  <p>This is my logging configuration:</p>
  
  <pre><code>private Serilog.Core.Logger ConfigureLogger(IHostingEnvironment env)
  {
      Serilog.Debugging.SelfLog.Enable(Console.Error);
  
      // Base configuration
      var logger = new LoggerConfiguration()
          .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
          .MinimumLevel.Override("System", LogEventLevel.Warning)
          .Enrich.FromLogContext()
          .Enrich.WithMachineName()
          .Enrich.WithThreadId();
  
      // Configure Sink: AWS CloudWatch
      var cloudWatchLogsClient = new AmazonCloudWatchLogsClient("ACCESS_KEY_ID", "SECRET_ACCESS_KEY",                                                                   RegionEndpoint.GetBySystemName(awsConfig.CloudWatchRegion));
      var logLevel = env.IsProduction() ? LogEventLevel.Information : LogEventLevel.Debug;
      logger.WriteTo.AmazonCloudWatch(new CloudWatchLogSinkOptions(env, logLevel), cloudWatchLogsClient);
  
      // Configure Sink: Console (only for Debug environment)
      if (env.IsDebug())
      {
          logger.WriteTo.Console(LogEventLevel.Debug);
      }
  
      return logger.CreateLogger();
  }
  </code></pre>
  
  <p>This is the implementation of CloudWatchSinkOptions:</p>
  
  <pre><code>   public class CloudWatchLogSinkOptions : ICloudWatchSinkOptions
      {
          public CloudWatchLogSinkOptions(IHostingEnvironment env, LogEventLevel level = LogEventLevel.Information)
          {
              LogGroupName += env.EnvironmentName;
              MinimumLogEventLevel = level;
          }
  
          #region Settings
  
          public LogEventLevel MinimumLogEventLevel { get; set; }
          public int BatchSizeLimit { get; set; } = 100;
          public TimeSpan Period { get; set; } = TimeSpan.FromSeconds(10);
          public LogGroupRetentionPolicy LogGroupRetentionPolicy { get; set; } = LogGroupRetentionPolicy.OneYear;
          public bool CreateLogGroup { get; set; } = true;
          public string LogGroupName { get; set; } = "WebApi-ApplicationLog/";
          public ILogStreamNameProvider LogStreamNameProvider { get; set; } = new DefaultLogStreamProvider();
          public ITextFormatter TextFormatter { get; set; }= new SerilogTextFormatter();
          public byte RetryAttempts { get; set; } = 5;
          public int QueueSizeLimit { get; set; }
  
          #endregion
  
  
          #region Defaults
  
          public const LogEventLevel DefaultMinimumLogEventLevel = LogEventLevel.Information;
          public const int DefaultBatchSizeLimit = 100;
          public const bool DefaultCreateLogGroup = true;
          public const byte DefaultRetryAttempts = 5;
          public static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(10);
  
          #endregion
  
      }
  </code></pre>
  
  <p>I believe I have included all required Serilog packages:</p>
  
  <p><a href="https://i.stack.imgur.com/hH4sG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hH4sG.png" alt="enter image description here"></a></p>
  
  <p>And finally, I have provided Lambda with the appropriate access to CloudWatch Logs:</p>
  
  <p><a href="https://i.stack.imgur.com/iJ19R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iJ19R.png" alt="enter image description here"></a></p>
  
  <p>I'm not sure where to go from here.  As I stated previously, this works great from by dev (Debug) environment.  It just doesn't work from Lambda, and SelfLog produces no error output.</p>
  
  <p>Anyone have some suggestions to resolve this?  I appreciate the help! </p>