log4net에서 PostgreSql로 내보내기

PgSQL은 점점 강해지고 있습니다.작은 프로젝트에서 로그를 sqlite로 출력하는 것은 매우 좋다. 큰 것은 특히 장기적으로 실행해야 하는 프로그램이PostgreSQL로 출력하는 것과 비교하면 윈도 서비스에 하숙하는 것도 현재 디렉터리를 System32로 보는 경우에 더욱 적합하다.
프로파일을 직접 업로드합니다.
<!--     PostgreSql    ,  Windows Service                           -->
    <appender name="AdoNetAppender_PostgreSQL_All" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="10"/>
      <connectionType value="Npgsql.NpgsqlConnection, Npgsql"/>
      <!--PostgreSql     -->
      <connectionString value="Server=127.0.0.1;Port=5432;User Id=postgres;Password=tm;Database=postgres;"/>
      <!--PostgreSql     -->
      <!--    PostgreSql          ,   "
                 Ormlite,      
      <commandText value="INSERT INTO "Log" 
                   ("AppDomain", "AspnetCache", "AspnetContext", "AspnetRequest", "AspnetSession", 
                   "Logger", "Date", "Identity", "Level", "Location", "Exception",
                   "Message", "Thread", "NDC", "StackTraceDetail", "UserName", "UTCDate")
                    VALUES
                    (:AppDomain, :AspnetCache, :AspnetContext, :AspnetRequest, :AspnetSession, :Logger, :Date, :Identity, :Level, :Location, :Exception,
                    :Message, :Thread, :NDC, :StackTraceDetail, :UserName, :UTCDate)"/>
      -->
      <!--    Ormlite    ,       -->
            <commandText value="INSERT INTO log 
                   (app_domain, aspnet_cache, aspnet_context, aspnet_request, aspnet_session, 
                   logger, date_time, identity, level, location, exception,
                   message, thread, ndc, stack_trace_detail, user_name, utc_date)
                    VALUES
                    (:AppDomain, :AspnetCache, :AspnetContext, :AspnetRequest, :AspnetSession, :Logger, :Date, :Identity, :Level, :Location, :Exception,
                    :Message, :Thread, :NDC, :StackTraceDetail, :UserName, :UTCDate)"/>
      <parameter>
        <parameterName value="AppDomain"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%appdomain"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="AspnetCache"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%aspnet-cache"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="AspnetContext"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%aspnet-context"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="AspnetRequest"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%aspnet-request"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="AspnetSession"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%aspnet-session"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Logger"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Date"/>
        <dbType value="DateTime"/>
        <layout type="log4net.Layout.RawTimeStampLayout"/>
      </parameter>
      <parameter>
        <parameterName value="Identity"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%identity"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Level"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Location"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%location"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Exception"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.ExceptionLayout">
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Message"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="Thread"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="NDC"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%ndc"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="StackTraceDetail"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%stacktracedetail{10}"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="UserName"/>
        <dbType value="String"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%username"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="UTCDate"/>
        <dbType value="DateTime"/>
        <layout type="log4net.Layout.RawUtcTimeStampLayout"/>
      </parameter>
    </appender>

실행할 때 현재 디렉터리에 Npgsql이 있어야 합니다.dll, 그리고 PgSQL에 표를 작성하여 좋은 사람이 끝까지 하고 Ormlite가 생성한 SQL을 바칩니다.
-- Table: log

-- DROP TABLE log;

CREATE TABLE log
(
  id serial NOT NULL,
  date_time timestamp without time zone NOT NULL,
  thread text,
  level text,
  logger text,
  message text,
  exception text,
  stack_trace_detail text,
  location text,
  identity text,
  app_domain text,
  user_name text,
  ndc text,
  utc_date timestamp without time zone,
  aspnet_cache text,
  aspnet_context text,
  aspnet_request text,
  aspnet_session text,
  CONSTRAINT log_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE log
  OWNER TO postgres;

-- Index: idx_log_level

-- DROP INDEX idx_log_level;

CREATE INDEX idx_log_level
  ON log
  USING btree
  (level COLLATE pg_catalog."default");

-- Index: uidx_log_date

-- DROP INDEX uidx_log_date;

CREATE UNIQUE INDEX uidx_log_date
  ON log
  USING btree
  (date);

스티커를 보내고 나서야 시스템이 "를 큰따옴표로 해석한 다음

좋은 웹페이지 즐겨찾기