This project has moved and is read-only. For the latest updates, please go here.

Can't log to ASP.NET database

Nov 1, 2010 at 11:16 AM

Hi;

First of all thank you for provide and maintain such an amazing project.
I'm getting a error when trying to log to a database using the asp.net sql provider. I'm able to see the error when It fallsback to the xml file provider but can't figure out how to fix it.

I'm running .NET 4, Visual Studio 2010 and SQL 2008 R2 under Windows Server 2008 R2.
My tests are performed using the built in VS2010 web server.

Here is the XML log with the AspNetSqlLogginProvider error:

<LogEntry>
	<EventTime>2010-11-01T06:02:46.9487343-04:00</EventTime>
	<Severity>Information</Severity>
	<Message>URL authorization succeeded for the request. (Event Code: 4003)</Message>
	<Source>WebSuccessAuditEvent</Source>
</LogEntry>
<LogEntry>
	<EventTime>2010-11-01T06:02:46.9487343-04:00</EventTime>
	<Severity>Error</Severity>
	<Message>The event could not be logged with provider 'AspNetSqlLogger'.</Message>
	<Source>CuttingEdge.Logging.Web.AspNetSqlLoggingProvider</Source>
	<Exception>
		<Message>Object reference not set to an instance of an object.</Message>
		<StackTrace>   at CuttingEdge.Logging.Web.AspNetSqlLoggingProvider.SaveExceptionToDatabase(SqlTransaction transaction, Exception exception, Int32 parentEventId, Nullable`1 parentExceptionId)
   at CuttingEdge.Logging.SqlLoggingProvider.SaveExceptionChainToDatabase(SqlTransaction transaction, Exception exception, Int32 eventId)
   at CuttingEdge.Logging.SqlLoggingProvider.LogWithinTransaction(LogEntry entry, SqlTransaction transaction)
   at CuttingEdge.Logging.SqlLoggingProvider.LogInternal(LogEntry entry)
   at CuttingEdge.Logging.LoggingProviderBase.CuttingEdge.Logging.ILogger.Log(LogEntry entry)</StackTrace>
	</Exception>
</LogEntry>

And here is my we.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
  </configSections>  
  <connectionStrings>
    <add name="SMPanelConnection" connectionString="data source=.\SQLEXPRESS;Initial Catalog=smpanel;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
    <add name="SMPanelEntities" connectionString="metadata=res://*/Code.SMPanelModel.csdl|res://*/Code.SMPanelModel.ssdl|res://*/Code.SMPanelModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=smpanel;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <logging defaultProvider="AspNetSqlLogger">
    <providers>
      <add name="AspNetSqlLogger"
        type="CuttingEdge.Logging.Web.AspNetSqlLoggingProvider, CuttingEdge.Logging"
        fallbackProvider="XmlLogger"
        connectionStringName="SMPanelConnection"
        threshold="Information"
        applicationName="SMPanel"
        userNameRetrievalType="Membership"
        logQueryString="True"
        logFormData="False"
      />
      <add name="XmlLogger"
        type="CuttingEdge.Logging.XmlFileLoggingProvider, CuttingEdge.Logging"
        path="App_Data/log.xml"
        description="XML file logging provider" />      
    </providers>
  </logging>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Login.aspx" timeout="2880" />
    </authentication>
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SMPanelConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SMPanelConnection" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="SMPanelConnection" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>    
    <httpModules>
      <!-- We're defining the AspNetExceptionLoggingModule here. -->
      <add name="ExceptionLogger"
          type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
    </httpModules>
    <healthMonitoring heartbeatInterval="0" enabled="true">
      <providers>
        <!-- We're configuring the web event provider here. -->
        <add name="LoggingWebEventProvider"
          type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
          loggingProvider="AspNetSqlLogger" />
      </providers>
      <rules>
        <add name="Custom Event Provider"
           eventName="All Events"
           provider="LoggingWebEventProvider"
           profile="Default" />
      </rules>
    </healthMonitoring>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

I hope you can help me with tha.
Thanks in advance.

Nov 1, 2010 at 4:34 PM
Edited Nov 1, 2010 at 4:47 PM

I Ebrito,

Let me start by saying that a reusable framework such as CuttingEdge.Logging should never throw an NullReferenceException.
At the very least the framework should have told you which value or argument is null. This is something I will fix, but this doesn't
directly solve your problem.

There are two possible reasons I can think of. First is a bug in the framework (the code supplied a null value to the
SaveExceptionToDatabase method). The other one is a bug in the logging_AddException stored procedure (the procedure
returned null).

Did you happen to change the default implementation of the logging_AddException stored procedure?

Nov 1, 2010 at 11:00 PM

Hey, first off all thank you for your attention and I didn't change the default implementation.
When I though it could be a bug with the SQL script (the one for ASP.NET) i removed the tables and store procedures and let the framework create them.
I also tried "userNameRetrievalType" to "None" and got the same result.

So, since my Intention was to use it to log error and user activity to a databse, I couldn't even start :-(

Nov 2, 2010 at 12:06 AM

You experienced a bug in the latest version (v1.3) of the framework. I created a work item for this and fixed it.
You can grab the code from codeplex to build your own private version or wait for the next release.

Thank you for reporting this bug.