Closed ShaharPrishMSFT closed 3 years ago
Is this your full configuration? No appsettings.json
?
If so, please refer to the docs on configuration:
Description | Default value | Notes | |
---|---|---|---|
Files | An array of LogFileOptions which define the settings of the individual log files. | There is an important change compared to the older versions: you must explicitly define at least one log file, otherwise the provider won't log anything. |
Otherwise, please verify that the process has the sufficient file system permissions on the RootPath
directory. (As you're using a temp directory, this shouldn't be the problem.)
On a side note, the logger creates the log directory if it doesn't exist, so you can safely remove the following lines:
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
If I don't create the folder, I get an exception on setting the value to Root:
System.IO.DirectoryNotFoundException
HResult=0x80070003
Message=C:\Users\shaharp\AppData\Local\Temp\Paros.Logs\
Source=Microsoft.Extensions.FileProviders.Physical
StackTrace:
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at Karambolo.Extensions.Logging.File.PhysicalFileAppender..ctor(String root)
at Karambolo.Extensions.Logging.File.FileLoggerOptions.set_RootPath(String value)
at ComputeService.Program.<>c.1.Configure(String name, TOptions options) at Microsoft.Extensions.Options.OptionsFactory
1.Create(String name)
at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.
What's the minimum set of properties I need to set on the the single File object I create in the Files array? Just creating an array with a single instantiation of the LogFileOptions class, does not work either.
Ok, let's first make clear which version of the lib you are using. My answer applies to v3.0 or later. In older versions the log directory wasn't created automatically unless you set EnsureBasePath
to true
.
Sorry for my oversight. FileAccessMode
was introduced in v3.0, so you obviously aren't using an older version.
Meanwhile I realized that my answer wasn't completely right, either. RootPath
must exist as this is the root directory of the underlying file provider. So the correct setup in your case is something like this:
.AddFile(c =>
{
c.RootPath = Path.GetTempPath();
c.BasePath = "Paros.Logs";
c.MaxFileSize = 10_000_000;
c.FileAccessMode = Karambolo.Extensions.Logging.File.LogFileAccessMode.KeepOpenAndAutoFlush;
c.Files = new[]
{
new Karambolo.Extensions.Logging.File.LogFileOptions { Path = "default.log" }
};
});
What's the minimum set of properties I need to set on the the single File object I create in the Files array? Just creating an array with a single instantiation of the LogFileOptions class, does not work either.
As you can see above, you need to specify at least the Path
property of the log file (which is relative to BasePath
).
Thanks. That solved my isseus.
I have the following code - nothing in appsettings or anywhere...
And no logs are being created.
What else am I missing?