On 2017-12-01 14:34, "[email protected]"<[email protected]> wrote:
>
>
> On 2017-11-30 23:07, Matt Sicker <[email protected]> wrote:
> > You should be able to create one the same way you create any other appender
> > using programmatic configuration.
> >
> > On 30 November 2017 at 06:36, [email protected] <[email protected]>
> > wrote:
> >
> > > Hi log4j2 users,
> > >
> > > I want to create jdbc appender using programmatic configuration.
> > >
> > > Please provide the programmatic configuration if you already have or guide
> > > me to create it.
> > >
> > > P.S. I am able to create JDBCAppender using xml configuration
> > >
> > > Thanks
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
> >
> >
> > --
> > Matt Sicker <[email protected]>
> > Hi Matt,
>
> I am able to add "tableName" attribute for JDBC AppenderComponentBuilder
> But not the remaining stuff like
> ConnectionFactory class,method and Columns.
>
> Please help
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
> What I've tried until now:
ConfigurationBuilder<BuiltConfiguration> builder =
ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setConfigurationName("myConfig");
builder.setStatusLevel(Level.ERROR);
ColumnConfig[] columnConfigs =
new ColumnConfig[] {
ColumnConfig.newBuilder()
// .setConfiguration(builder.)
.setName("myUsername")
.setPattern("")
.setLiteral("%X{username}")
.setEventTimestamp(false)
.setUnicode(false)
.setClob(false)
.build(),
ColumnConfig.newBuilder()
// .setConfiguration(this)
.setName("myAction")
.setPattern("%X{action}")
.setLiteral(null)
.setEventTimestamp(false)
.setUnicode(false)
.setClob(false)
.build(),
ColumnConfig.newBuilder()
// .setConfiguration(this)
.setName("myTimeStamp")
.setPattern(null)
.setLiteral(null)
.setEventTimestamp(true)
.setUnicode(false)
.setClob(false)
.build()
};
ConnectionSource factoryMethodConnectionSource =
FactoryMethodConnectionSource.createConnectionSource(
"com.database.ConnectionFactory", "getDatabaseConnection");
AppenderComponentBuilder appenderBuilder =
builder
.newAppender("databaseAppender", "JDBC")
.addAttribute("tableName", âmyTableâ);
builder.add(appenderBuilder);
builder.add(
builder
.newLogger("DbLogger", Level.DEBUG)
.add(builder.newAppenderRef("databaseAppender"))
.addAttribute("additivity", false));
LoggerContext ctx = Configurator.initialize(builder.build());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]