logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arsenmkrt <mkrtchyan.ar...@gmail.com>
Subject Add or change parameter value dynamicly
Date Tue, 31 Jul 2007 12:16:43 GMT

Hello. I have a table T_Audit where i want to write my log messages in oracle
db. it has a field processid that i want to put dynamically its the
identifier of the process that is doing log not the real process just the id
of process table from my database so i decide to write my appender like this 
 
 <appender name="AdoNetAppender_Oracle"
type="log4net.Appender.AdoNetAppender">
    <connectionType value="System.Data.OracleClient.OracleConnection,
System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
    <connectionString value="my connection string" />
    <commandText value="INSERT INTO T_AUDIT
(LOG_ID,RM_METADATA_ID,PROCESS_ID,PROCESS_TYPE,LOG_DATE,SEVERITY,LOG_MESSAGE)
VALUES
(SEQ_AUDIT.NEXTVAL,:rmmetadataid,:processid,:processtype,:log_date,:log_level,:message)"
/>
    <bufferSize value="128" />
    <parameter>
      <parameterName value=":rmmetadataid" />
      <dbType value="Int32" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="285" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value=":processtype" />
      <dbType value="Int32" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="1" />
      </layout>
    </parameter>    
    <parameter>
      <parameterName value=":log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.RawTimeStampLayout" />
    </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=":message" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message" />
      </layout>
    </parameter>
  </appender>

i add the processID parameter programiticaly like this 

 log4net.Repository.Hierarchy.Hierarchy hierarchy = null;
            log4net.Repository.Hierarchy.Logger logger = null;
            hierarchy
=(log4net.Repository.Hierarchy.Hierarchy)LoggerManager.GetRepository(Assembly.GetCallingAssembly());

            //// Configure root logger
            logger = hierarchy.Root;
            log4net.Appender.AdoNetAppender adoAppender =
(log4net.Appender.AdoNetAppender)logger.GetAppender("AdoNetAppender_Oracle");

            log4net.Appender.AdoNetAppenderParameter processIdParam = new
log4net.Appender.AdoNetAppenderParameter();
            processIdParam.ParameterName = ":processid";
            processIdParam.DbType = System.Data.DbType.Int32;
            PatternLayout pl = new PatternLayout();
            RawLayoutConverter rlc = new RawLayoutConverter();
            pl.ConversionPattern = ProcessID.ToString();
            processIdParam.Layout = (IRawLayout)rlc.ConvertFrom(pl);
            adoAppender.AddParameter(processIdParam);
            adoAppender.ActivateOptions();
         
            hierarchy.Configured = true;
and call xmlconfigurator to configure logging before adding parameter
programiticaly. but it doesn't work. please help to solve this problem...
note that when i add procesis parameter manually to config file it all works
well.
-- 
View this message in context: http://www.nabble.com/Add-or-change-parameter-value-dynamicly-tf4192651.html#a11923011
Sent from the Log4net - Users mailing list archive at Nabble.com.


Mime
View raw message