-
Notifications
You must be signed in to change notification settings - Fork 0
AspNetSession layout renderer
Julian Verdurmen edited this page Jan 8, 2016
·
5 revisions
ASP.NET Session variable.
Supported in .NET and Mono
##Configuration Syntax
${aspnet-session:variable=String;evaluateAsNestedProperties:boolean}
##Parameters ###Rendering Options
- variable - Session variable name.
-
EvaluateAsNestedProperties - boolean. Default:
false
. Evaluate thevariable
as nested properties. The dots in thevariable
are special interpreted. See example below.
##Remarks Use this layout renderer to insert the value of the specified variable stored in the ASP.NET Session dictionary.
##Examples
Log the username in the session.
In the C# code:
Session["username"] = "johnDoe";
Config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" layout="${aspnet-session:Variable=Username}/>
</rules>
</nlog>
Will print "JohnDoe"
In the C# code:
Session["user"] = new UserInfo { Name= "johnDoe", Id = 100};
Config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" layout="${aspnet-session:Variable=User.Name:EvaluateAsNestedProperties=true}/>
</rules>
</nlog>
Will print "JohnDoe"
- Search in documentation
- Getting started
- Examples
- External articles and tutorials
- FAQ
- Platform support
- Advanced Configuration file options
- Filtering log messages
- [Using Time Sources](Time Source)
- Visual Studio support
- Who is using NLog
- [Write custom extensions](Extending NLog)