https://github.com/u1035/disklogger
Lightweight logger that writes data to files
https://github.com/u1035/disklogger
csharp log logger logging logging-library netstandard20 nuget-package
Last synced: about 2 months ago
JSON representation
Lightweight logger that writes data to files
- Host: GitHub
- URL: https://github.com/u1035/disklogger
- Owner: u1035
- License: mit
- Created: 2022-10-29T05:50:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T06:24:45.000Z (over 3 years ago)
- Last Synced: 2025-03-03T12:38:51.625Z (over 1 year ago)
- Topics: csharp, log, logger, logging, logging-library, netstandard20, nuget-package
- Language: C#
- Homepage: https://www.nuget.org/packages/DiskLogger
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/DiskLogger)
[](https://www.nuget.org/packages/DiskLogger)

# DiskLogger
Lightweight application log library that writes debug files to disk.
Targets .NET Standard 2.0 and can be used with different kinds of projects.
Produces new file for each day, can use file prefix, writes information about log function caller ([CallerMemberName], [CallerFilePath], [CallerLineNumber]), adds timezone info to log record timestamp.
(under slow lazy development)
Inspired by NLog, but I wanted to create simple solution by myself.
## Usage
At first we need to initialize LogManager somewhere at application entry point:
```csharp
LogManager = new LogManager("C:\\Logs", "myApp");
```
This will make logger to create log files like
```
C:\Logs\myApp-2022-10-29.log
C:\Logs\myApp-2022-10-30.log
...
```
Then we need to create logger for class or context we need:
```csharp
var _logger = LogManager.ForContext();
//or
var _logger = LogManager.ForContext("SomeContext");
```
In code you can use logger like this:
```csharp
_logger.Trace("Some trace message");
_logger.Notice("Some notice message");
_logger.Debug("Some debug message");
_logger.Info("Some info message");
_logger.Warning("Some warning message");
_logger.Error($"Some error message: {exception.Message}");
_logger.Fatal("Some fatal error message");
```
and get the following line in your log file:
> 2022-10-29T22:41:22.5116388+03:00|WorkerClass|PrintInfo|MainViewModel.cs|17|Debug|Message text
Where you will find time of event, context, name of function, source file name and line, severity of the message, and your message.