Search code examples
c#loggingnlog

Does NLog raise an event when something is logged?


I want to be able to catch this event in order to not only log the message but to insert this message into a ListView simultaneously. Is there such an event?


Solution

  • The comments are right, but to elaborate:

    In NLog log-events aren't event-driven (there are no event handlers), but route-driven. So every event is matched to the defined routes (the <rules> in your nlog.config).

    With the routes you can send the log-events so 0, 1 or multiple targets and create fallbacks, filtering etc.

    So if you need the logevents in a ListView, you need to search for a target to use or write a custom one.

    Full list of targets are here: https://nlog-project.org/config/?tab=targets

    Writing a custom target is explained here: https://github.com/NLog/NLog/wiki/How-to-write-a-custom-target

    Happy logging :)