Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krishamagar opened this issue Sep 1, 2023 · 5 comments
Open

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

krishamagar opened this issue Sep 1, 2023 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@krishamagar
Copy link

krishamagar commented Sep 1, 2023

{
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
Copy link
Author

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

@SeppPenner SeppPenner self-assigned this Nov 16, 2023
@SeppPenner SeppPenner added the question Further information is requested label Nov 16, 2023
@tkrafael
Copy link

I think you need to use forward slash to save correctly

@tkrafael
Copy link

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
Copy link
Contributor

I think you need to use forward slash to save correctly

I think this is correct, yes.

@DanielZabek
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants