Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog to PostgreSQL connection

I have a problem in connecting with the postgres database through NLog.

I made the database with query:

CREATE TABLE system_logging
( 
ID serial primary key,
entered_date date default Now(),
log_application varchar(200) NULL, 
log_date character varying(100) NULL, 
log_level character varying(100) NULL, 
log_logger character varying(8000) NULL, 
log_message character varying(8000) NULL, 
log_machine_name character varying(8000) NULL, 
log_user_name character varying(8000) NULL, 
log_call_site character varying(8000) NULL, 
log_thread character varying(100) NULL, 
log_exception character varying(8000) NULL, 
log_stacktrace character varying(8000) NULL 
)

And my connecting target is defined as:

<target name="database" xsi:type="Database"
         connectionString="Server=127.0.0.1;Port=5432;User Id=test;Password=t;Database=Test;">
      <commandText>Insert into "system_logging" ("log_date","log_level","log_logger","log_message","log_machine_name","log_user_name","log_call_site","log_thread","log_exception","log_stacktrace") values (:time_stamp,:level,:logger,:message,:machinename,:user_name,:call_site,:threadid,:log_exception,:stacktrace)</commandText>

   <parameter name="@time_stamp" layout="${longdate}"/> 
  <parameter name="@level" layout="${level}"/> 
  <parameter name="@logger" layout="${logger}"/> 
  <parameter name="@message" layout="${message}"/> 
  <parameter name="@machinename" layout="${machinename}"/> 
  <parameter name="@user_name" layout="${windows-identity:domain=true}"/> 
  <parameter name="@call_site" layout="${callsite:filename=true}"/>

  <parameter name="@threadid" layout="${threadid}"/> 
  <parameter name="@log_exception" layout="${exception}"/> 
  <parameter name="@stacktrace" layout="${stacktrace}"/>
</target>  
like image 651
Anish Shrestha Avatar asked Jan 08 '23 03:01

Anish Shrestha


1 Answers

So I searched on and got an answer :

 <target name="database" type="Database"> 
    <dbProvider>
        Npgsql.NpgsqlConnection,Npgsql,Version=3.0.3.0,Culture=neutral,PublicKeyToken=5d8b90d52f46fda7
    </dbProvider>
    <connectionString> 
        Server=127.0.0.1;Port=5432;User Id=postgres;Password=postgres;Database=sample;
    </connectionString> 
    <commandText> 
        insert into system_logging(log_date,log_level,log_logger,log_message,log_machine_name, log_user_name, log_call_site, log_thread, log_exception, log_stacktrace) values(@time_stamp, @level, @logger, @message,@machinename, @user_name, @call_site, @threadid, @log_exception, @stacktrace); 
    </commandText> 
    <parameter name="@time_stamp" layout="${longdate}"/> 
    <parameter name="@level" layout="${level}"/> 
    <parameter name="@logger" layout="${logger}"/> 
    <parameter name="@message" layout="${message}"/> 
    <parameter name="@machinename" layout="${machinename}"/> 
    <parameter name="@user_name" layout="${windows-identity:domain=true}"/> 
    <parameter name="@call_site" layout="${callsite:filename=true}"/>
    <parameter name="@threadid" layout="${threadid}"/> 
    <parameter name="@log_exception" layout="${exception}"/> 
    <parameter name="@stacktrace" layout="${stacktrace}"/>
</target> 
like image 193
Anish Shrestha Avatar answered Jan 16 '23 21:01

Anish Shrestha