I'm running 15 parallel Powershell processes so I can't log to a file, and I can't flood the Application Event viewer. Logging to a database makes perfect sense. My problem seems to be a common one, but the only solution I've found is to hand code the Log4Net implementation rather than s开发者_开发技巧etting up a straightforward config file. This sounds wrong to me. I can't imagine there's no way around this config issue, but perhaps someone can point me to a more complete answer.
Full discussion of the issue exists at: Social.Technet
My config is per Apache specs for Oracle 9 databases: Apache Config Docs
The first parameter uses the RawTimeStampLayout and works like a charm. The second parameter attempts to use the PatternLayout and fails.
<parameter>
<parameterName value=":log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value=":message" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
When I attempt to add a message using PatternLayout, I receive:
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_Oracle] of type [log4net.Appender.AdoNetAppender].
Reported error follows.
System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
Parameter name: converterType
Exactly like everyone else, if I use the RawPropertyLayout instead of PatternLayout I no longer receive the error, but I only log NULLs for those fields.
Per the discussion on Social.Technet, one way to make the logging work is to use code to create the parameters like this:
$param2 = New-Object log4net.Appender.AdoNetAppenderParameter
$param2.ParameterName = "@log_level"
$parm2Layout=New-Object log4net.Layout.PatternLayout("%level")
$param2.Layout = New-Object log4net.Layout.Layout2RawLayoutAdapter($parm2Layout)
$param2.DbType = "String"
$param2.Size = 50
$sqlAppender.AddParameter($param2)
Note that the PatternLayout is created then manually fed to the 2RawLayout Adapter. This seems to be the step missing in the config conversion process.
Does anyone know of a better way? Does anyone have a working PowerShell-Log4Net-Oracle config laying around?
Are you sure you can't log to a file? There's a +MinimalLock
configuration for FileAppender
that has log4net only taking locks while appending. The log4net file appender is damn fast, too.
精彩评论