Can't log to ASP.NET database

Nov 1, 2010 at 10:16 AM


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 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:

	<Message>URL authorization succeeded for the request. (Event Code: 4003)</Message>
	<Message>The event could not be logged with provider 'AspNetSqlLogger'.</Message>
		<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>

And here is my we.config:

<?xml version="1.0" encoding="utf-8"?>
    <section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
    <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" />
  <logging defaultProvider="AspNetSqlLogger">
      <add name="AspNetSqlLogger"
        type="CuttingEdge.Logging.Web.AspNetSqlLoggingProvider, CuttingEdge.Logging"
      <add name="XmlLogger"
        type="CuttingEdge.Logging.XmlFileLoggingProvider, CuttingEdge.Logging"
        description="XML file logging provider" />      
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
        <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <authentication mode="Forms">
      <forms loginUrl="~/Login.aspx" timeout="2880" />
        <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="/" />
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SMPanelConnection" applicationName="/" />
    <roleManager enabled="true">
        <clear />
        <add connectionStringName="SMPanelConnection" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
      <!-- We're defining the AspNetExceptionLoggingModule here. -->
      <add name="ExceptionLogger"
          type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
    <healthMonitoring heartbeatInterval="0" enabled="true">
        <!-- We're configuring the web event provider here. -->
        <add name="LoggingWebEventProvider"
          type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
          loggingProvider="AspNetSqlLogger" />
        <add name="Custom Event Provider"
           eventName="All Events"
           profile="Default" />
    <modules runAllManagedModulesForAllRequests="true" />

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

Nov 1, 2010 at 3:34 PM
Edited Nov 1, 2010 at 3: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 10: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 1, 2010 at 11:06 PM

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.