Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log current page url with NLog

Tags:

asp.net

nlog

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?

like image 242
Mike737 Avatar asked Sep 02 '11 05:09

Mike737


People also ask

How do you log into the NLog?

Logging messages with NLog is easy. To log, you need a reference to a Logger from something called LogManager : Logger log = LogManager. GetCurrentClassLogger();

What is NLog Web AspNetCore?

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.


1 Answers

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.

like image 94
ccellar Avatar answered Sep 26 '22 01:09

ccellar