serilog-contrib / Serilog.Sinks.AmazonS3

Serilog.Sinks.AmazonS3 is a library to save logging information from Serilog to Amazon S3. The idea there was to upload log files to Amazon S3 to later evaluate them with Amazon EMR services.
MIT License
21 stars 21 forks source link

How to save the log file inside of folder? #60

Open krishamagar opened 1 year ago

krishamagar commented 1 year ago

{ 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 commented 1 year ago

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

tkrafael commented 7 months ago

I think you need to use forward slash to save correctly

tkrafael commented 7 months ago

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

SeppPenner commented 7 months ago

I think you need to use forward slash to save correctly

I think this is correct, yes.

DanielZabek commented 4 months ago

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_...