首页 新闻 会员 周边

log4Net写进数据库无反应

0
悬赏园豆:10 [已解决问题] 解决于 2018-05-16 15:24

1.Oracle数据库连接的dll信息

 

2.web.config的配置信息

  1 <log4net>
  2     <appender name="ADONetAppender" type="log4net.Appender.AdoNetAppender">
  3       <bufferSize value="0" />
  4       <connectionType value="Oracle.ManagedDataAccess.Client.OracleConnection,Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  5       <connectionString value="Password=密码;User ID=用户名;Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = PORT))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = 数据库实例名称) ));" />
  6       <!--<connectionString value="Data Source=//IP:port/实例;User ID=USERID;Password=Password;" />-->
  7       <!--<commandText value="INSERT INTO Sys_Log (LogDate,Thread,log_level,Logger,Message) VALUES (:log_date,:thread,:log_level,:logger,:message)" />-->
  8       <commandText value="INSERT INTO LOG4NET (LOG_ID, LOG_DATE, LOG_LEVEL, LOG_IDENTITY, LOG_MESSAGE, LOG_EXCEPTION, LOG_LOGGER, LOG_SOURCE) VALUES (LOG4NET_SEQ.nextval, :log_date, :log_level, :log_identity, :log_message, :log_exception, :logger, :source)" />
  9       <parameter>
 10         <parameterName value=":log_date" />
 11         <dbType value="DateTime" />
 12         <layout type="log4net.Layout.RawTimeStampLayout">
 13         </layout>
 14       </parameter>
 15       <parameter>
 16         <parameterName value=":log_level" />
 17         <dbType value="String" />
 18         <size value="10" />
 19         <layout type="log4net.Layout.PatternLayout">
 20           <conversionPattern value="%level" />
 21         </layout>
 22       </parameter>
 23       <parameter>
 24         <parameterName value=":log_identity" />
 25         <dbType value="String" />
 26         <size value="100" />
 27         <layout type="log4net.Layout.PatternLayout">
 28           <conversionPattern value="%identity" />
 29         </layout>
 30       </parameter>
 31       <parameter>
 32         <parameterName value=":log_message" />
 33         <dbType value="String" />
 34         <size value="4000" />
 35         <layout type="log4net.Layout.PatternLayout">
 36           <conversionPattern value="%m" />
 37         </layout>
 38       </parameter>
 39       <parameter>
 40         <parameterName value=":log_exception" />
 41         <dbType value="String" />
 42         <size value="4000" />
 43         <layout type="log4net.Layout.PatternLayout">
 44           <conversionPattern value="%exception" />
 45         </layout>
 46       </parameter>
 47       <parameter>
 48         <parameterName value=":logger" />
 49         <dbType value="String" />
 50         <size value="255" />
 51         <layout type="log4net.Layout.PatternLayout">
 52           <conversionPattern value="%logger" />
 53         </layout>
 54       </parameter>
 55       <parameter>
 56         <parameterName value=":source" />
 57         <dbType value="String" />
 58         <size value="1000" />
 59         <layout type="log4net.Layout.PatternLayout">
 60           <conversionPattern value="%file:%line" />
 61         </layout>
 62       </parameter>
 63       <!--<parameter>
 64         <parameterName value=":log_date" />
 65         <dbType value="DateTime" />
 66         <layout type="log4net.Layout.RawTimeStampLayout">
 67         </layout>
 68       </parameter>
 69       <parameter>
 70         <parameterName value=":log_level" />
 71         <dbType value="String" />
 72         <size value="10" />
 73         <layout type="log4net.Layout.PatternLayout">
 74           <conversionPattern value="%level" />
 75         </layout>
 76       </parameter>
 77       <parameter>
 78         <parameterName value=":thread" />
 79         <dbType value="String" />
 80         <size value="255" />
 81         <layout type="log4net.Layout.PatternLayout">
 82           <conversionPattern value="%thread" />
 83         </layout>
 84       </parameter>
 85       <parameter>
 86         <parameterName value=":message" />
 87         <dbType value="String" />
 88         <size value="4000" />
 89         <layout type="log4net.Layout.PatternLayout">
 90           <conversionPattern value="%m" />
 91         </layout>
 92       </parameter>
 93       <parameter>
 94         <parameterName value=":logger" />
 95         <dbType value="String" />
 96         <size value="255" />
 97         <layout type="log4net.Layout.PatternLayout">
 98           <conversionPattern value="%logger" />
 99         </layout>
100       </parameter>-->
101     </appender>
102     <appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
103       <param name="File" value="Log\\LogInfo\\" />
104       <param name="AppendToFile" value="true" />
105       <param name="MaxFileSize" value="10240" />
106       <param name="MaxSizeRollBackups" value="100" />
107       <param name="StaticLogFileName" value="false" />
108       <param name="DatePattern"  value="yyyy\\yyyyMM\\yyyyMMdd'.txt'" />
109       <param name="RollingStyle" value="Date" />
110       <layout type="log4net.Layout.PatternLayout">
111         <param name="ConversionPattern" value="%n日志时间:%d [%t] %n日志级别:%-5p %n日 志 类:%c [%x] %n%m %n" />
112       </layout>
113     </appender>
114 
115     <logger name="loginfo">
116       <level value="All"/>
117       <appender-ref ref="ADONetAppender" />
118     </logger>
119     <!--<root>
120       <level value="All"/>
121       <appender-ref ref="ADONetAppender" />
122       --><!--<appender-ref ref="InfoAppender" />--><!--
123     </root>-->
124   </log4net>
125   <!--日志的配置结束-->

 

 

 

 

3.后台调用的代码

public ActionResult Index()
        {
            
            Log.Info("这是我写的first第一行log");
            Log.Info("这是我写的second第二行log");
            Log.Info("这是我写的thrid第三行log");


            return View();
        }
 public class Log
    {
        //static readonly log4net.ILog log = log4net.LogManager.GetLogger("loginfo");
        static readonly log4net.ILog log=LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 
        public static void Info(string info)
        {
            //ILog log = LogManager.GetLogger("log4netlogger");
            log.Info(info);



        }
    }

 

以上是我配置的所有信息,从网上查找了很多资料,没看出什么区别来,请个各位大神帮忙找一下问题,为啥数据不能插入Oracle数据库,万分谢谢

侯小北的主页 侯小北 | 初学一级 | 园豆:39
提问于:2018-05-16 09:56

图片无法显示

dudu 6年前

@dudu: 愁的一批,哈哈

侯小北 6年前

@dudu: 现在好啦,帮忙看一下吧,大神

侯小北 6年前
< >
分享
最佳答案
0

取消注释下面的代码

//static readonly log4net.ILog log = log4net.LogManager.GetLogger("loginfo");
收获园豆:10
dudu | 高人七级 |园豆:30948 | 2018-05-16 10:21

已经试过啦,这种方式也不行,有没有能单独测试一下这个数据库是不是连接成功啦??也就是测试一下下边这两句管用不??

<connectionType value="Oracle.ManagedDataAccess.Client.OracleConnection,Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<connectionString value="Password=密码;User ID=用户名;Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = PORT))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = 数据库实例名称) ));" />
侯小北 | 园豆:39 (初学一级) | 2018-05-16 10:26

@侯小北: 可以在 Visual Studio 的 Data Sources 中测试一下数据库连接

dudu | 园豆:30948 (高人七级) | 2018-05-16 10:30

@dudu: 这样的话只能测试出connectionString,测试不出connectionType吧???

侯小北 | 园豆:39 (初学一级) | 2018-05-16 10:36

@侯小北: 在.csproj中可以看到 Oracle.ManagedDataAccess.Client.OracleConnection 这个程序集的信息

dudu | 园豆:30948 (高人七级) | 2018-05-16 10:42
其他回答(1)
0

配置的细节问题

侯小北 | 园豆:39 (初学一级) | 2018-05-16 15:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册