Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing logs to files using Serilog is not working

I have an ASP .NET based application that uses Serilog for logging and I want to test it by writing my logs to files. I am using Serilog and Serilog.Sinks.File So far, the code looks like this:

_perfLogger = new LoggerConfiguration()
                .WriteTo.File("C:\\Users\\andav\\Desktop\\NewTest\\logger\\perf.txt")
                .CreateLogger();

_perfLogger.Write(LogEventLevel.Information, "{@LogDetail}", infoToLog);

But all my files are empty or are not created and I am not getting any errors.

Am I doing something wrong?

Thank you.

like image 670
Alexandra Avatar asked Oct 18 '25 16:10

Alexandra


1 Answers

You may be able to if you add read/write permission for IIS_IUSRS on the directory.

I usually put the log directory in the same directory as my IIS app and do the following:

You need local admin permissions:

  1. Right-click on the directory that you want to log file in
  2. Choose properties
  3. Go to Security tab
  4. Click Edit
  5. Click Add
  6. Type IIS_IUSRS
  7. Click on Check Names

If it cannot find it then click on locations

  • Click on your computer name and click ok
  • Now click on check names and it should resolve.

...

  1. Click OK
  2. Give the Modify Permission
  3. Click OK

Logging "should" work

If it is a directory outside of inetpub, I am not sure but worth a try.

-Gina

like image 75
Gina Marano Avatar answered Oct 20 '25 06:10

Gina Marano