Serilog.Sinks.AmazonS3 icon indicating copy to clipboard operation
Serilog.Sinks.AmazonS3 copied to clipboard

How to save the log file inside of folder?

Open krishamagar opened this issue 2 years ago • 5 comments

{ var logger = new LoggerConfiguration().WriteTo .AmazonS3( "folder1\folder2\" + fileName + "\" + date + "\" + "Log_", bucketName, Amazon.RegionEndpoint.APSouth1, awsAccessKey, awsSecretKey, restrictedToMinimumLevel: LogEventLevel.Verbose, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", new CultureInfo("en-US"), levelSwitch: levelSwitch, rollingInterval: Serilog.Sinks.AmazonS3.RollingInterval.Day, encoding: Encoding.Unicode, failureCallback: e => Console.WriteLine($"An error occured in my sink: {e.Message}") ) .CreateLogger(); logger.Information(message); }

krishamagar avatar Sep 01 '23 04:09 krishamagar

I have this path but the file is not saving in the mentioned path.

krishamagar avatar Sep 01 '23 04:09 krishamagar

I think you need to use forward slash to save correctly

tkrafael avatar Apr 23 '24 21:04 tkrafael

Also, once you configured this sink, date will never change. I'm assuming you want to create files on different folders based on current date. In that case, you would like to read #30 that states it is necessary to use WriteTo.Map

tkrafael avatar Apr 23 '24 21:04 tkrafael

I think you need to use forward slash to save correctly

I think this is correct, yes.

SeppPenner avatar Apr 24 '24 08:04 SeppPenner

For me path doesn't work either. For those who have problems with saving logs somewhere deeper, set the bucketPath parameter.

From documentation:

bucketPath | Optionally add a sub-path for the bucket. Files are stored on S3 mytestbucket-aws/awsSubPath/log.txt in the example below. | bucketPath = "awsSubPath"

so, in your example:

var logger = new LoggerConfiguration().WriteTo
  .AmazonS3(
  "Log_",
  bucketName,
  Amazon.RegionEndpoint.APSouth1,
  awsAccessKey,
  awsSecretKey,
  bucketPath: "folder1/folder2",
  restrictedToMinimumLevel: LogEventLevel.Verbose,
  outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
  new CultureInfo("en-US"),
  levelSwitch: levelSwitch,
  rollingInterval: Serilog.Sinks.AmazonS3.RollingInterval.Day,
  encoding: Encoding.Unicode,
  failureCallback: e => Console.WriteLine($"An error occured in my sink: {e.Message}")
)
.CreateLogger();
logger.Information(message);

result will be bucketName/folder1/folder2/Log_...

DanielZabek avatar Jul 17 '24 10:07 DanielZabek