Log4Net File Appender Works, DB write does not



  • I have a log4net configuration that works when writing to the file appender but doesn't work when writing to a database.

    The config should work because it's my standard log4net config, and the database accepts data from other local apps. What can I possibly be missing?

    current web.config:

      <log4net>
        <appender name="FileAppender" type="log4net.Appender.FileAppender">
          <param name="File" value="log4net.log" />
          <param name="AppendToFile" value="true" />
          <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d - %m%n" />
          </layout>
        </appender>
        <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
          <bufferSize value="1" />
          <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          <connectionStringName value="LoggingDatabase" />
          <commandText value="INSERT INTO Log4Net_Error ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
          <parameter>
            <parameterName value="@log_date" />
            <dbType value="DateTime" />
            <layout type="log4net.Layout.RawTimeStampLayout" />
          </parameter>
          <parameter>
            <parameterName value="@thread" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%thread" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@log_level" />
            <dbType value="String" />
            <size value="50" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%level" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@logger" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%logger" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@message" />
            <dbType value="String" />
            <size value="4000" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%message" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@exception" />
            <dbType value="String" />
            <size value="2000" />
            <layout type="log4net.Layout.ExceptionLayout" />
          </parameter>
        </appender>
        <root>
          <level value="ALL" />
          <appender-ref ref="AdoNetAppender" />
          <appender-ref ref="FileAppender" />
        </root>
      </log4net>
    

    Edit: The application does have access to the particular database server - it uses a database on the same server already.



  • At this point, the only thing I can think is that the buffer isn't getting flushed to the database; this config on a console app with just one line that logs a string works fine.



  • Apparently I'm TR :WTF:, whatever version of Log4Net I happen to be using in this application doesn't have a connectionStringName property, and I have to set the connection string directly.



  • The logger could be encountering an error that forces a thread roll-back or abnormal termination (which would also imply roll-back). If that's the case, the write happens but is undone.



  • @CoyneTheDup said:

    The logger could be encountering an error that forces a thread roll-back or abnormal termination (which would also imply roll-back). If that's the case, the write happens but is undone.

    :wtf: Did you even bother to read the post before yours? This isn't t/1000



  • @rad131304 said:

    Did you even bother to read

    How can I do that and give dumb suggestions at the same time? Yeesh!



  • @CoyneTheDup said:

    give dumb suggestions

    About Coding Help

    Coding Help: The one place you would really hope not to get a "WTF" solution to your problem.


  • Since you clearly lack a humor nerve, let me put this in a different tone. You are correct. I overlooked the post preceding, As a result, my post was a WTF, for which I apologize. Satisfied?

    Now ask yourself this: Just what is the liklihood that I will ever try to help you, on anything, ever again?



  • Are you using the same database instance with other apps? Is it exactly the same log4net config that works in those apps? Does log4net throw any first-chance exceptions when trying to log?



  • @CoyneTheDup said:

    Since you clearly lack a humor nerve, let me put this in a different tone. You are correct. I overlooked the post preceding, As a result, my post was a WTF, for which I apologize. Satisfied?

    Now ask yourself this: Just what is the liklihood that I will ever try to help you, on anything, ever again?

    No, I have one; I just don't use it here. Again, read my posts. Jokes and :WTF: help not welcome in this section. It says so in our forum "rules". :wtf: questions are fine, of which mine is definitely one.



  • @Maciejasjmj said:

    Are you using the same database instance with other apps? Is it exactly the same log4net config that works in those apps? Does log4net throw any first-chance exceptions when trying to log?

    There was an error - I'm a :WTF: and didn't read the log. We were using an older version of Log4Net that didn't have the <connectionStringName> element. We fixed by upgrading Log4Net.


Log in to reply