简体   繁体   English

我可以使用NLog更新现有的日志条目吗?

[英]Can i update an existing log entry using NLog?

I am writing a windows service, that logs quite a few entries using NLog. 我正在编写Windows服务,该服务使用NLog记录了很多条目。
However when it starts logging errors (perhaps due to a longer internet outage), it is not relevant to log the same error every 10th or so seconds. 但是,当它开始记录错误(可能是由于更长的Internet中断时间)时,每10秒钟左右记录一次相同的错误并不重要。
So I tried to look for a way to update an existing log entry, using NLog, as it is familiar to me. 因此,我尝试使用NLog来寻找一种更新现有日志条目的方法,这对我来说是很熟悉的。 - But to no avail... -但无济于事...

Does anyone know of a way to update a single entry of a log, without rewriting the entirety of the file? 有谁知道更新日志的单个条目而不重写整个文件的方法吗?

The program is on a server, and writes to a local .txt file. 该程序在服务器上,并写入本地.txt文件。 Currently using NLog, but i am not sure if it is even possible with NLog. 当前正在使用NLog,但是我不确定是否可以使用NLog。 I have not been able to find anything on it. 我还找不到任何东西。

Thanks for any answers! 感谢您的任何答案!

I agree with Jehof. 我同意杰霍夫的观点。 Ideally, logging is append only. 理想情况下,日志记录仅是附加的。

As an alternative; 作为备选; you could potentially write your own custom NLog wrapper that filters duplicate log attempts within a timespan. 您可能会编写自己的自定义NLog包装器,以过滤某个时间段内重复的日志尝试。 see https://github.com/NLog/NLog/wiki/Targets-and-Wrappers for more information about NLog wrappers. 有关NLog包装器的更多信息,请参见https://github.com/NLog/NLog/wiki/Targets-and-Wrappers

This blog shows an example about how to write a NLog wrapper. 博客显示了有关如何编写NLog包装器的示例。 Although the NLog wrapper in this example does not fit your exact scenario, you could probably use it as a baseline for your implementation... 尽管此示例中的NLog包装器并不适合您的确切情况,但是您可以将其用作实现的基准...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM