Layout renderers aspnet-sessionid exception - what else can I try

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

Layout renderers aspnet-sessionid exception - what else can I try

shearichard

When I try to embed "${aspnet-request:serverVariable=REMOTE_ADDR}" into a layout I get an exception "LayoutRenderer cannot be found: 'aspnet-request'" thrown. (see below for details)

I've searched the forums and found a couple of solutions others have found to this problem but after implementing those changes I still get the exception. I'd be grateful to anyone who can review what I've done and point out the mistakes !

The project has references to both NLog.dll and NLog.extended.dll .

These are the 'NLog for .NET Framework 3.5' and both are version 2.0.0.0.

Both DLL's are in the same directory ('\bin' relative to the NLog.config).

An 'Add Assembly' section of NLog.config is used to reference the NLog.extended (see below).

I'm running the project directly out of Visual Studio. If I update NLog.config so that the reference to aspnet-request is removed then everything works as it should.

The NLog config looks like this :

<?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"
	  autoReload="true"
	  throwExceptions="true">

	<targets>
		<target name="fileall" xsi:type="File" fileName="${basedir}/DynamicContent/CRRDiagnosticsLog.txt" 
            layout="${longdate}|${aspnet-request:serverVariable=REMOTE_ADDR}|${level}|${message}"
			ArchiveEvery="Day"
			ArchiveFileName="${basedir}/DynamicContent/CRRUIDiagnosticsLog_{#####}.txt"
			ArchiveNumbering="Sequence" 
			maxArchiveFiles="28"
			/>
		<target name="fileerrors" xsi:type="File" fileName="${basedir}/DynamicContent/CRRErrorLog.txt" 
            layout="${longdate}|${level}|${message}|${stacktrace}"
			ArchiveEvery="Day"
			ArchiveFileName="${basedir}/DynamicContent/CRRUIErrorLog_{#####}.txt"
			ArchiveNumbering="Sequence"
		    maxArchiveFiles="28"	
			/>
	</targets>
  <extensions>
    <add assembly="NLog.Extended" />
  </extensions>

	<rules>
		<logger name="*" minlevel="Trace" writeTo="fileall"/>
		<logger name="*" minlevel="Error" writeTo="fileerrors"/>
	</rules>
</nlog>
... and the error screen looks like this ...
Server Error in '/' Application.
LayoutRenderer cannot be found: 'aspnet-request'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: LayoutRenderer cannot be found: 'aspnet-request'

Source Error:

Line 12:     public class Global : System.Web.HttpApplication
Line 13:     {
Line 14:         private static Logger _NLogLogger = LogManager.GetCurrentClassLogger();
Line 15: 
Line 16:         protected void Application_Start(object sender, EventArgs e)


Source File: C:\usr\foo\mytemp\20110609\TASUIRework-2\application-dotnet\TASDotNetWebSite\Global.asax.cs    Line: 14

Stack Trace:

[ArgumentException: LayoutRenderer cannot be found: 'aspnet-request']
   NLog.Config.Factory`2.CreateInstance(String name) +199
   NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, Tokenizer sr) +181
   NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configurationItemFactory, Tokenizer sr, Boolean isNested, String& text) +307
   NLog.Layouts.SimpleLayout.set_Text(String value) +87
   NLog.Layouts.SimpleLayout..ctor(String txt, ConfigurationItemFactory configurationItemFactory) +60
   NLog.Layouts.Layout.FromString(String layoutText, ConfigurationItemFactory configurationItemFactory) +53
   NLog.Layouts.Layout.FromString(String layoutText) +48
   NLog.Layouts.Layout.op_Implicit(String text) +31

[NLogConfigurationException: Error when setting property 'Layout' on File Target[fileall]]
   NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name, String value) +1222
   NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(Object targetObject, NLogXmlElement element, Boolean ignoreType) +274
   NLog.Config.XmlLoggingConfiguration.ParseTargetElement(Target target, NLogXmlElement targetElement) +166
   NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement targetsElement) +1033
   NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String baseDirectory) +1090
   NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String baseDirectory) +246
   NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) +276

[NLogConfigurationException: Exception occurred when loading configuration from C:\usr\foo\mytemp\20110609\TASUIRework-2\application-dotnet\TASDotNetWebSite\NLog.config]
   NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) +461
   NLog.Config.XmlLoggingConfiguration..ctor(String fileName) +230
   NLog.LogFactory.get_Configuration() +337
   NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey) +368
   NLog.LogFactory.GetLogger(String name) +84
   NLog.LogManager.GetCurrentClassLogger() +116
   TASDotNetWebSite.Global..cctor() in C:\usr\foo\mytemp\20110609\TASUIRework-2\application-dotnet\TASDotNetWebSite\Global.asax.cs:14

[TypeInitializationException: The type initializer for 'TASDotNetWebSite.Global' threw an exception.]
   TASDotNetWebSite.Global..ctor() +0
   ASP.global_asax..ctor() in c:\Users\Foo Barr\AppData\Local\Temp\Temporary ASP.NET Files\root\a42ef4ee\11e4b982\App_global.asax.tiwdxfkq.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +215
   System.Web.HttpApplicationFactory.FireApplicationOnStart(HttpContext context) +8882040
   System.Web.HttpApplicationFactory.EnsureAppStartCalled(HttpContext context) +136
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +92
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289


Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618