好多时候,在lognet中再写一次连接都是重复的,通过下面的方法可以读取在配置文件其它位置声明的数据库连接
using System; using log4net; using log4net.Config; using System.Configuration; using System.Collections.Specialized; using System.IO; namespace EtpService.Core
调用代码:
private static readonly ILog log = LogManager.GetLogger( typeof (AccountManager)); string conString = Log4net.GetConfig( " nhibernate " , 3 ); Log4net.ConfigConnection(conString, " EtpService.Core.AccountManager " , " ADONetAppender " ); 没有用上面的类生成Log,不知道怎么实现 类似static readonly 的功能
配置文件:
< configSections > < section name ="nhibernate" type ="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" /> < section name ="log4net" type ="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> < section name ="etp" type ="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </ configSections > < nhibernate > < add key ="hibernate.connection.provider" value ="NHibernate.Connection.DriverConnectionProvider" /> < add key ="hibernate.dialect" value ="NHibernate.Dialect.MsSql2000Dialect" /> < add key ="hibernate.connection.driver_class" value ="NHibernate.Driver.SqlClientDriver" /> < add key ="hibernate.connection.connection_string" value ="Password=sa;uid=sa;Initial Catalog=Etp;Data Source=dinghao" /> </ nhibernate >
相关文章:
2021-07-13
2021-06-09
2022-12-23
2022-12-23
2022-12-23
2022-12-23
2021-11-06
2021-08-05
猜你喜欢
2022-12-23
2022-12-23
2022-12-23
2022-12-23
2021-07-31
2021-07-13
2021-11-21
相关资源
下载
2021-06-06
下载
2021-06-05
下载
2022-12-17