I'm trying to log the current pages URL as part of our NLog layout. I've scoured the NLog layout variables and have come up with nothing.
Does anyone know how to get the current page URL as a variable for the layout? Also is it possible just to extract the domain name so this can be used in the EventLog source attribute?
Logging messages with NLog is easy. To log, you need a reference to a Logger from something called LogManager : Logger log = LogManager. GetCurrentClassLogger();
NLog is a flexible and free logging platform for various . NET platforms, including . NET standard. NLog makes it easy to write to several targets. (database, file, console) and change the logging configuration on-the-fly.
Use the Aspnet-request layout renderer.
<target xsi:type="Trace"
name="trace"
layout="${message} ${aspnet-request:serverVariable=Url}" />
You have full access to the request properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With