LayoutRenderer cannot be found: 'aspnet-user-identity'

3,014 views
Skip to first unread message

Glenn Lanier, II

unread,
Jul 3, 2013, 2:43:00 PM7/3/13
to nlog-...@googlegroups.com
I'm periodically getting the error:

LayoutRenderer cannot be found: 'aspnet-user-identity'


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-user-identity'

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: LayoutRenderer cannot be found: 'aspnet-user-identity']
   NLog.Config.Factory`2.CreateInstance(String name) +199
   NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr) +118
   NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr, Boolean isNested, String& text) +262
   NLog.Layouts.SimpleLayout..ctor(String txt, ConfigurationItemFactory configurationItemFactory) +96
   NLog.Internal.PropertyHelper.TryNLogSpecificConversion(Type propertyType, String value, Object& newValue, ConfigurationItemFactory configurationItemFactory) +160
   NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name, String value, ConfigurationItemFactory configurationItemFactory) +565

[NLogConfigurationException: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo]
   NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name, String value, ConfigurationItemFactory configurationItemFactory) +1375
   NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(Object targetObject, NLogXmlElement element, Boolean ignoreType) +303
   NLog.Config.XmlLoggingConfiguration.AddArrayItemFromElement(Object o, NLogXmlElement element) +157
   NLog.Config.XmlLoggingConfiguration.SetPropertyFromElement(Object o, NLogXmlElement element) +31
   NLog.Config.XmlLoggingConfiguration.ParseTargetElement(Target target, NLogXmlElement targetElement) +984
   NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement targetsElement) +1054
   NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String baseDirectory) +942
   NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) +259

Now, I've verified that I am including a reference to NLog and NLog.Extended. Both DLLs exist in the bin folder of my web application. My NLog.config contains:

<?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">

    <extensions>
        <add assembly="NLog.Extended" />
    </extensions>
   
   <targets>
        <target name="file" xsi:type="File" fileName="${basedir}/Logs/${date:format=yyyy.MM.dd}.log" />

        <!-- write log message to database -->
        <target xsi:type="Database" name="DbLog">
            <!-- Provider -->
            <dbProvider>System.Data.SqlClient</dbProvider>

            <!-- Default connection string -->
            <!--
            <connectionString>__VALID_CONNECTION_STRING_HERE__</connectionString>-->

            <!-- SQL command to be executed for each entry -->
            <commandText>__VALID_MS_SQL_SPROC_HERE</commandText>

            <!-- parameters for the command -->
            <parameter name="@LogTime" layout="${date}"></parameter>
            <parameter name="@Username" layout="${aspnet-user-identity}"></parameter>
            <parameter name="@LogLevel" layout="${level}"></parameter>
            <parameter name="@Logger" layout="${logger}" />
            <parameter name="@Message" layout="${message}" />
            <parameter name="@HostIp" layout="${machinename}"></parameter>
            <parameter name="@RemoteIp" layout="${aspnet-request:severVariable=REMOTE_ADDR}"></parameter>
        </target>
        <target name="dailyFile"
                xsi:type="File"
                fileName="${basedir}/logs/${date:format=yyyy.MM.dd}.log"
                layout="${longdate}|${aspnet-user-identity}|${level}|${logger}|${message}|${machinename}|${aspnet-request:serverVariable=REMOTE_ADDR}" />
    </targets>

    <rules>
        <logger name="*" minlevel="Trace" writeTo="dailyFile" />
        <logger name="*" minlevel="Trace" writeTo="DbLog" />
    </rules>
</nlog>

If I redeploy my web application to the server, it works for some time (I can't say how long). At some point it starts giving me this error message.

Any clue why this is happening, and/or what I need to do to keep it from happening?

Thanks.

--G



Kim Christensen

unread,
Jul 3, 2013, 5:44:09 PM7/3/13
to nlog-...@googlegroups.com

Sounds like it could be related to the periodical AppDomain restart occurring in IIS. But how to solve it and why it happens I don't know. I'll try to look into it.

Glenn Lanier, II

unread,
Jul 3, 2013, 6:07:52 PM7/3/13
to nlog-...@googlegroups.com
I have another, older application on the same server where I build the entire configuration in code (partially due to needing to change connection strings based on server). I create the configuration in Application_Start. It doesn't seem to have this problem.

The application with the problem using the NLog.config file, and in Application_Start, I iterate through the targets, looking for the database target with a specific name, changing the connection string on a match. It works fine (until it doesn't).

I don't know if this additional information helps or not; thanks for any help you can provide!

--G


On Wed, Jul 3, 2013 at 4:44 PM, Kim Christensen <kimwo...@gmail.com> wrote:

Sounds like it could be related to the periodical AppDomain restart occurring in IIS. But how to solve it and why it happens I don't know. I'll try to look into it.

--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nlog-users+...@googlegroups.com.
To post to this group, send email to nlog-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kim Christensen

unread,
Jul 10, 2013, 5:25:07 PM7/10/13
to nlog-...@googlegroups.com
Do you know if this also happens if you aren't modifying the configuration in Application_Start? Are automatic reload enabled in the configuration file?

Glenn Lanier, II

unread,
Jul 17, 2013, 2:10:28 PM7/17/13
to nlog-...@googlegroups.com
After removing the references to aspnet-request and aspnet-user-identity from my configuration file, I got another, non-NLog related error. In tracking down the solution to that error, I gave my user write access to the Temporary Internet Files directory. I was able to put the aspnet-request/aspnet-user-identity items back in the config file and have not seen any errors in more than one week.

My application connects to multiple databases and has to impersonate multiple users, depending on the database. I verified that I was always the correct user prior to calling an NLog command, but it looks like the issue had more to do with a [Windows] user trying to load a DLL that referenced NLog.Extended and not having the permission to copy it into the temporary internet files location.

Thanks to all that provided help and/or looked at this.

--G





--G



Glenn Lanier, II

unread,
Jul 17, 2013, 2:11:15 PM7/17/13
to nlog-...@googlegroups.com
Yes, it happens even if I hardcode my connection string. No, automatic reloads are not enabled.

--G

Kim Christensen

unread,
Jul 18, 2013, 8:01:19 AM7/18/13
to nlog-...@googlegroups.com

Glad to know this have been solved

Reply all
Reply to author
Forward
0 new messages