加密 log4net AdoNetAppender 使用的连接字符串
我想加密 log4net AdoNetAppender。
可以在不加密整个附加器的情况下完成此操作吗?
Dion Olsthoorn 发表了有关在代码中设置连接字符串的博客,但我更喜欢在专用于日志记录的配置文件中执行此操作,因为它将使用与应用程序的其余部分不同的数据库。
以下是来自 http://logging.apache 的示例配置。 org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=SQLSVR;initial catalog=test_log4net;integrated security=false;persist security info=True;User ID=sa;Password=sa" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
</parameter>
</appender>
I'd like to encrypt the connection string used by the log4net AdoNetAppender.
Can this be done without encrypting the entire appender?
Dion Olsthoorn blogged about setting the connection string in code, but I'd prefer to do it in a config file that is dedicated to logging as it will be using a different database to the rest of the application.
Below is the sample config from http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=SQLSVR;initial catalog=test_log4net;integrated security=false;persist security info=True;User ID=sa;Password=sa" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
</parameter>
</appender>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当前源已经具有 ConnectionStringName 属性,它完全可以满足您的需求。
ConnectionStringName 属性是在修订版 607748 中引入的。 版本 1.2.10 是修订版 395324,它是与此相比相当古老。
如果您愿意使用未发布的代码,您可以获取最新的源代码并自行编译。 您也可能只获得更新的 AdoNetAppender 类,尽管它可能依赖于 log4net 核心的其他更新。
The current source already have the ConnectionStringName property that does exactly what you are looking for.
The ConnectionStringName property was introduced in revision 607748. Version 1.2.10 is revision 395324 which is quite old compared to that.
If you're comfortable working with unreleased code you could get the latest source and compile it yourself. You could probably also get just the updated AdoNetAppender class though it could have dependencies on other updates to the log4net core.
我已经能够通过继承 log4net AdoNetAppender 并添加一个名为 ConnectionStringName 的属性来解决此问题。
如果设置了此选项,它将从 web.config 连接字符串中读取连接字符串并将其传递到底层 AdoNetAppender。
我仍然热衷于一种将所有日志记录配置保存在单个文件中并且仍然允许加密连接字符串的解决方案。
I've been able to work around this by inheriting from the log4net AdoNetAppender and adding a property called ConnectionStringName.
If this is set it will read the connection string from the web.config connection strings and pass it through to the underlying AdoNetAppender.
I'd still be keen for a solution that keeps all the logging configuration in a single file and still allows the connection string to be encrypted.