Skip to content

Commit 97f2970

Browse files
committed
2 parents ee1deb0 + 08d3adf commit 97f2970

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

README.md

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,70 @@
1-
# Extensions.Logging.File
2-
Simple rolling file logger for Microsoft.Extensions.Logging
1+
# Bleess.Extensions.Logging.File
2+
Simple rolling file logger for Microsoft.Extensions.Logging with no 3rd party dependencies
3+
4+
Very similar implementation to other standard MS logging providers such as Console Logger in dotnet 5.
5+
6+
## Features include
7+
- Text or Json output
8+
- Rolling files
9+
- Standard Microsoft.Extensions.Logging configuration (similar to Console logging, etc)
10+
- Plugable custom formatters
11+
- Abitity to change settings while running (using IOptionsMonitor)
12+
- Logging scopes
13+
- High performance using dedicated write thread and message queue
14+
15+
16+
This project is very similar to nReco/logging with a few additions noteably logging scopes, json output, streamlined configuration, and abiltity to modify settings while running.
17+
18+
## Usage
19+
The log provider is configured just like any other Microsoft.Extensions.Logging providers. There are extensions methods on the ILogBuilder to add the provider.
20+
21+
When using Host.CreateDefaultBuilder you only need to call AddFile(), and the logger will be configured using configuration providers. There are also other overloads to configure the logger using options callbacks etc.
22+
23+
```
24+
logBuilder.AddFile();
25+
```
26+
27+
## Configuration
28+
29+
Below is a sample configuration for the file provider. The values shown are the defaults.
30+
31+
```
32+
{
33+
"Logging": {
34+
35+
"File": {
36+
"IncludeScopes": true,
37+
"Path": "logs/log.txt",
38+
"MaxNumberFile": 7,
39+
"MaxFileSizeInMB": 50, // this can be decimal
40+
"FormatterName": "simple", // simple or json
41+
"Append": true,
42+
"logLevel": {
43+
"default": "Information"
44+
}
45+
},
46+
47+
"logLevel": {
48+
"default": "Information"
49+
}
50+
}
51+
}
52+
53+
```
54+
55+
## Formatting
56+
There are two built in formatters. Simple text and Json. The formatters have a few limited options.
57+
58+
TODO: Document formatter configuration
59+
60+
Custom formatters can be plugged in the same way as with Console Logger in dotnet 5.
61+
62+
63+
## Rolling Behavior
64+
Log files can have a max file size at which time a new file will be create with a increment id. You can also specify a maximum nuber of files to retain. Once the maximum number of files has been reteached the oldest will be overwritten.
65+
66+
## Credits
67+
- Most of the code was a port from dotnet source code (specifically Microsoft.Extensions.Logging.Console) https://github.com/dotnet/runtime/tree/master/src/libraries/Microsoft.Extensions.Logging.Console
68+
- The FileWriter was adapted from https://github.com/nreco/logging
69+
70+

0 commit comments

Comments
 (0)