File-Logger | NET Core for .NET 5 Web API
kandi X-RAY | File-Logger Summary
kandi X-RAY | File-Logger Summary
An ASP.NET Core for .NET 5 Web API which extends .NET Core's Logging Feature to Log to Text files in a HostedService.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of File-Logger
File-Logger Key Features
File-Logger Examples and Code Snippets
Community Discussions
Trending Discussions on File-Logger
QUESTION
I'm trying to implement a simple file-logger object, with the possibility to truncate the file when its size reaches a threshold.
I am using a StreamWriter
, which gets written to at each call of the method Log()
. In order to decide when to truncate, I am checking the StreamWriter.BaseStream.Length
property before each write and, if it is bigger than the threshold, I close the StreamWriter
, create a new file and open the StreamWriter
on that file.
For example, if I set the threshold to 10Mb files, it will create a new file each 10Mb of written data.
Under normal load (let's say 3-4 seconds between calls to Log()
), everything works as it should. However, the product which is going to use this logger will work with lots of data and required logging every 1 second, even less.
The problem is that the logger seems to completely ignore the creation of the new file(and opening the new stream), failing to truncate it and keeps writing to the existing stream.
I also tried to manually compute the stream's length, hoping it would be a problem with the stream, but it does not work.
I have found out that going step by step with the debugger makes it work correctly, but it does not solve my problem. Logging each second seems to make the program skip the UpdateFile()
method entirely.
ANSWER
Answered 2020-Nov-10 at 15:41Your code looks "fine", so I'm guessing the issue is being caused by multiple threads accessing the InternalLog
method at once. Your code is not thread safe as it does not use any locking mechanisms. The easiest and probably totally sufficient solution for your project is to add a locking object at class level:
QUESTION
In my code I am using 'node-file-logger' for logging purposes and also using 'eslint'. Eslint is showing warning for using log.Debug with fewer arguments than expected.
I want to know that how can I disable this Eslint rule without modifying my existing log.Debug statements?
node-file-logger logging interface for debug:
...ANSWER
Answered 2020-Mar-06 at 11:00You can disable the eslint rule for any line using this
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install File-Logger
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page