You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Rob Richardson <RD...@rad-con.com> on 2014/05/30 20:47:16 UTC

AdoNetAppender not working PostgreSQL database using Npgsql

Greetings!

I am trying to get an AdoNetAppender to work, and I'm not succeeding.  For now, all I'm trying to do is to write a constant message to a database table.  Along with the AdoNetAppender, I have a RollingFileAppender that is working well.  I should get one record in my log table for every line in the log file.  I'm not getting anything.

This project is built in Microsoft Visual Studio 2008, and is running under Windows 7.  I am using the ConfigureAndWatch() method to set up my application's logger.

Here is the configuration file I'm using:

<?xml version="1.0" encoding="utf-8"?>
<log4net>
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="CraneSimulator2.log" />
    <appendToFile value="true" />
    <maxSizeRollBackups value="90" />
    <rollingStyle value="Size" />

    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date - %message%newline" />
    </layout>
  </appender>
<appender name="NpgsqlAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="5" />
    <connectionType value="Npgsql.NpgsqlConnection, Npgsql, Version=2.0.11.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
    <connectionString value="Server=127.0.0.1;Port=5434;Database=CraneSimulatorLog;User Id=xxxx;Password=yyyyyyyy;" />
    <commandText value="INSERT INTO Log (message) VALUES ('This is a log message')" />
</appender>
  <root>
     <level value="DEBUG" />
     <appender-ref ref="RollingFile" />
     <appender-ref ref="NpgsqlAppender" />
  </root>

</log4net>

Before this, I tried using ODBC, and that didn't work either.

Can anyone tell me what's wrong, or suggest a way in which I can see what error is happening?  There are no error messages in the PostgreSQL log files.

Thanks very much!

RobR

Re: AdoNetAppender not working PostgreSQL database using Npgsql

Posted by Dominik Psenner <dp...@gmail.com>.
Glad you were able to sort it out on your own and be sure that it would
have taken ages to find this. :-)

Cheers


2014-05-30 21:32 GMT+02:00 Rob Richardson <RD...@rad-con.com>:

>  Sorry to bother you.  The problem turns out to be what seems to me an
> unbelievable bug (feature?) in the PostgreSQL administration tool PGAdmin
> shipped with version 9.3:  if you use that tool to create a table, the name
> of the table includes double quotes.
>
>
>
> I decided, just for grins, to try the insert statement I specified in my
> configuration file:
>
> INSERT INTO Log (message) VALUES ('This is a log message')
>
> It didn’t work!
>
> Neither did:
>
> INSERT INTO log (message) VALUES ('This is a log message')
>
> But this worked:
>
> INSERT INTO “Log” (message) VALUES ('This is a log message')
>
>
>
> But I don’t know how to include double quotes inside an XML attribute.
> So, I deleted the table and recreated it manually, making sure not to use
> double-quotes around the identifiers.  Once I did that, I got the log
> messages in the table as expected.
>
>
>
> RobR
>



-- 
Dominik Psenner

RE: AdoNetAppender not working PostgreSQL database using Npgsql

Posted by Rob Richardson <RD...@rad-con.com>.
Sorry to bother you.  The problem turns out to be what seems to me an unbelievable bug (feature?) in the PostgreSQL administration tool PGAdmin shipped with version 9.3:  if you use that tool to create a table, the name of the table includes double quotes.

I decided, just for grins, to try the insert statement I specified in my configuration file:
INSERT INTO Log (message) VALUES ('This is a log message')
It didn't work!
Neither did:
INSERT INTO log (message) VALUES ('This is a log message')
But this worked:
INSERT INTO "Log" (message) VALUES ('This is a log message')

But I don't know how to include double quotes inside an XML attribute.  So, I deleted the table and recreated it manually, making sure not to use double-quotes around the identifiers.  Once I did that, I got the log messages in the table as expected.

RobR