Get request URL path in configuration

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Get request URL path in configuration

I want to log full url path of request where exception occured to my database target. I use following configuration to get url:

<variable name="CurrentUri" value="http://${aspnet-request:serverVariable=SERVER_NAME}:${aspnet-request:serverVariable=SERVER_PORT}${aspnet-request:serverVariable=SCRIPT_NAME}?${aspnet-request:serverVariable=QUERY_STRING}"/>

This pattern has problems with conditional params (like ? in begin of query string when there is not query string.. etc.).
I tried "when layout renderer" + "Condition" for conditional formatting, but without success ( ), maybe I am using bad syntax..

For example for get "" or "" I tried:

.....${when:when=length(${aspnet-request:serverVariable=QUERY_STRING}) > 0 : inner=?${aspnet-request:serverVariable=QUERY_STRING}}

But without success :) = "..NLog.Conditions.ConditionParseException: Invalid punctuation: $"

I think, that problem is two nested layouts.. but how I can I use these kind conditions in variables?
Do you know any simpler solution to get fullUrl of request? (without custom layout class, just in config file..)