Log4Net 到 Oracle -> PatternLayout 失败并显示“converterType is null”
我正在运行 15 个并行 Powershell 进程,因此无法登录到文件,也无法淹没应用程序事件查看器。记录到数据库非常有意义。我的问题似乎是一个常见问题,但我找到的唯一解决方案是手动编写 Log4Net 实现代码,而不是设置一个简单的配置文件。这对我来说听起来不对。我无法想象没有办法解决这个配置问题,但也许有人可以给我指出一个更完整的答案。
该问题的完整讨论位于: Social.Technet
我的配置符合 Oracle 9 数据库的 Apache 规范:Apache 配置文档
第一个参数使用 RawTimeStampLayout 并且工作起来就像一个魅力。第二个参数尝试使用 PatternLayout 但失败。
<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>
当我尝试使用 PatternLayout 添加消息时,我收到:
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
与其他人一样,如果我使用 RawPropertyLayout 而不是 PatternLayout,我将不再收到错误,但我只记录这些字段的 NULL。
根据 Social.Technet 上的讨论,进行日志记录的一种方法是使用代码创建如下参数:
$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)
请注意,PatternLayout 是创建后手动输入到 2RawLayout 适配器的。这似乎是配置转换过程中缺少的步骤。
有谁知道更好的方法吗?有人有可用的 PowerShell-Log4Net-Oracle 配置吗?
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 setting 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定无法登录到文件吗?有一个
+MinimalLock
配置FileAppender
使 log4net 仅在附加时获取锁定。 log4net 文件附加器也非常快。Are you sure you can't log to a file? There's a
+MinimalLock
configuration forFileAppender
that has log4net only taking locks while appending. The log4net file appender is damn fast, too.