NLog.Windows.Forms 4.2 has been released!
28 Dec 2015NLog.Windows.Forms 4.2 has been released including a new feature for the RichTextBoxTarget — it is now possible to add clickable links to log messages.
Features
This release contains the following features:
RichTextBox links
It is now possible to add clickable links to messages show in in the RichTextBox control and receive whole event info in the link click handler.
To do this, set target’s newly introduced supportLink
parameter to true
and use new ${rtb-link}
layout renderer to specify link part of the layout.
To receive link click events, add a handler to RichTextBoxTarget.LinkClicked
event. Use RichTextBoxTarget.GetTargetByControl(RichTextBox control)
static method to access the target attached to a specific RichTextBox control.
Not sure how to use it? Here are few examples.
Exception details example
When logging exceptions to RichTextBoxTarget you have to find a compromise between flooding the control with huge stacktraces and missing important information. Not anymore! Now you may long only a short description into textbox, and show whole details when user clicks a link:
Just setup a proper layout (don’t forget to enable supportLinks
)
And add a link click handler:
Focusing at specific item example
Sometimes you may need to not only notify user of some problem (like validation failing), but also help him navigate to the problematic item (for example when the list is huge). In this case you may store item’s id of some sort in the LogEventInfo.Property
, turn it into a link and navigate to the item in link click handler:
The layout:
Validation code:
Event handling code:
Hope you could find more useful applications of this new feature!
A note on 4.1 release
In case you are not sure what RichTextBoxTarget.ReInitializeAllTextboxes(this)
call does, then you might have missed a feature added in 4.1 release. It improves the RichTextBoxTarget functional by allowing it to be configured and initialized before the actual control is created. Check allowAccessoryFormCreation
and messageRetention
options description in the target’s documentation