CodeWithSaar.Extensions.Logging.File
1.0.0-beta4
See the version list below for details.
dotnet add package CodeWithSaar.Extensions.Logging.File --version 1.0.0-beta4
NuGet\Install-Package CodeWithSaar.Extensions.Logging.File -Version 1.0.0-beta4
<PackageReference Include="CodeWithSaar.Extensions.Logging.File" Version="1.0.0-beta4" />
paket add CodeWithSaar.Extensions.Logging.File --version 1.0.0-beta4
#r "nuget: CodeWithSaar.Extensions.Logging.File, 1.0.0-beta4"
// Install CodeWithSaar.Extensions.Logging.File as a Cake Addin #addin nuget:?package=CodeWithSaar.Extensions.Logging.File&version=1.0.0-beta4&prerelease // Install CodeWithSaar.Extensions.Logging.File as a Cake Tool #tool nuget:?package=CodeWithSaar.Extensions.Logging.File&version=1.0.0-beta4&prerelease
CodeWithSaar.Extensions.Logging.File
A very easy to use file logger provider implementation for Microsoft.Extensions.Logging.
Refer to the Known-limitations before you use this in production environment.
Getting Started
Add NuGet Package:
dotnet add package CodeWithSaar.Extensions.Logging.File
In ASP.NET Core project, enable the logging provider:
... // Add services to the container. builder.Services.AddLogging(loggingBuilder =>{ loggingBuilder.AddFile(); }); ...
Check out the example project.
Run the application and see the log output to
output.log
, and you are expected to see log entries like this:[2022-04-12 12:12:42, Microsoft.Extensions.Hosting.Internal.Host, Debug] Hosting starting [2022-04-12 12:12:42, Microsoft.Hosting.Lifetime, Information] Now listening on: https://localhost:7038 [2022-04-12 12:12:42, Microsoft.Hosting.Lifetime, Information] Now listening on: http://localhost:5125 [2022-04-12 12:12:42, Microsoft.Hosting.Lifetime, Information] Application started. Press Ctrl+C to shut down. [2022-04-12 12:12:42, Microsoft.Hosting.Lifetime, Information] Hosting environment: Development [2022-04-12 12:12:42, Microsoft.Hosting.Lifetime, Information] Content root path: D:\Repos\CodeWithSaar.Extensions.Logging\examples\WebAPIExample\ [2022-04-12 12:12:42, Microsoft.Extensions.Hosting.Internal.Host, Debug] Hosting started [2022-04-12 12:12:44, Microsoft.Hosting.Lifetime, Information] Application is shutting down... [2022-04-12 12:12:44, Microsoft.Extensions.Hosting.Internal.Host, Debug] Hosting stopping [2022-04-12 12:12:44, Microsoft.Extensions.Hosting.Internal.Host, Debug] Hosting stopped
Customization
Set a different file name
There are generally 2 ways to set log configurations.
By code:
builder.Services.AddLogging(loggingBuilder => { loggingBuilder.AddFile(opt => opt.OutputFilePath = "newfilename.log"); });
By configuration file (Typically, appsettings.json):
{ // General logging "Logging": { "LogLevel": { "Default": "Debug" }, // File provider overwrites "FileProvider": { // Output to output.v2.log file "OutputFilePath": "output.v2.log", // Specify a different logging level "LogLevel":{ "Default": "Information" } } } }
Set different logging levels
Logging levels could be set in through appsettings.json
/ appsettings.Development.json
or whatever the configuration providers in your project.
It would take the default settings like this:
{
// Logging Information or above to file
"Logging": {
"LogLevel": {
"Default": "Debug"
}
}
}
Or it could be set to it's own:
{
// Default logging level of Debug
"Logging": {
"LogLevel": {
"Default": "Debug"
},
"FileProvider":
{
// Output to output.v2.log file
"OutputFilePath": "output.v2.log",
// Specify a different logging level of Information for logs output to the file.
"LogLevel":{
"Default": "Information"
}
}
}
}
Other customizations
There are more options than just the filename. All supports the settings from either the delegate in code or the configuration providers (like it in appsettings.json). Refer to FileLoggerOptions.cs for more properties to be customized like: ShowFullCategoryName
, TimestampFormat
, etc.
Known limitations
- Scope needs to be implemented;
- Writing performance needs to be benchmarked;
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- System.Threading.Channels (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 727 | 5/9/2022 |
1.0.0-beta6 | 242 | 5/2/2022 |
1.0.0-beta5 | 237 | 4/19/2022 |
1.0.0-beta4 | 208 | 4/12/2022 |
1.0.0-beta2 | 186 | 4/12/2022 |
1.0.0-beta1 | 185 | 4/12/2022 |