IIS上的WCF log4net与AdoNetAppender无法正常工作

时间:2012-11-26 11:28:04

标签: wcf log4net iis-express

我正在尝试在一个要托管在IIS上的wcf服务中配置log4net,目前正在使用iis express ...问题是我无法在数据库中记录这些值。我正在使用.net 4.0和wshttpbinding为wcf。

我已经通过一些文章并将buffersize设置为1.并且还启用了调试..但没有任何反应:(

这是我的服务web.config

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

  <system.web>
    <trust level="Full"/>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>
  <system.serviceModel>

    <services>
      <service name="IVRService.IVR">
        <endpoint address="http://localhost:63589/IVR.svc" binding="wsHttpBinding"
          bindingConfiguration="" name="IVRWS" contract="IVRService.IIVR" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
  </system.serviceModel>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="data source=*****;initial catalog=*****;integrated security=true;persist security info=True;User ID=*****;Password=*****" />
      <commandText value="INSERT INTO IVRServiceLog ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="AdoNetAppender" />

    </root>
  </log4net>

  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add
            name="textWriterTraceListener"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="C:\tmp\log4net.txt" />
      </listeners>
    </trace>
  </system.diagnostics>

</configuration>

这就是我的代码

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class IVR : IIVR
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}

我不确定这有什么问题?请帮忙

提前致谢, 勒凯什

0 个答案:

没有答案