1,设置了web.congig
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configsections>
<section name="log4net" type="log4net.config.log4netconfigurationsectionhandler, log4net" />
</configsections>
<system.web>
<!--  DYNAMIC DEBUG COMPILATION
          Set compilation debug="true" to enable ASPX debugging.  Otherwise, setting this value to
          false will improve runtime performance of this application. 
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.
    -->
<compilation defaultLanguage="c#" debug="true" />
<!--  CUSTOM ERROR MESSAGES
          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. 
          Add <error> tags for each of the errors you want to handle.          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running 
           on the local Web server. This setting is recommended for security purposes, so 
           that you do not display application detail information to remote clients.
    -->
<customErrors mode="RemoteOnly" />
<!--  AUTHENTICATION 
          This section sets the authentication policies of the application. Possible modes are "Windows", 
          "Forms", "Passport" and "None"          "None" No authentication is performed. 
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to 
           its settings for the application. Anonymous access must be disabled in IIS. 
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then 
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    -->
<authentication mode="Windows" />
<!--  AUTHORIZATION 
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous 
          (unauthenticated) users.
    -->
<authorization>
<allow users="*" /> <!-- Allow all users -->
<!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
</authorization>
<!--  APPLICATION-LEVEL TRACE LOGGING
          Application-level tracing enables trace log output for every page within an application. 
          Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
          trace information will be displayed at the bottom of each page.  Otherwise, you can view the 
          application trace log by browsing the "trace.axd" page from your web application
          root. 
    -->
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<!--  SESSION STATE SETTINGS
          By default ASP.NET uses cookies to identify which requests belong to a particular session. 
          If cookies are not available, a session can be tracked by adding a session identifier to the URL. 
          To disable cookies, set sessionState cookieless="true".
    -->
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false" timeout="20" />
<!--  GLOBALIZATION
          This section sets the globalization settings of the application. 
    -->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>

<log4net>
<root>
<level value="all" />
<appender-ref ref="adonetappender" />
</root>
<!-- 
<logger name="testapp.logging"> 
<level value="all"/> 
<appender-ref ref="adonetappender" /> </logger> 
-->
<appender name="adonetappender" type="log4net.appender.adonetappender">
<buffersize value="10" />
<connectiontype value="system.data.sqlclient.sqlconnection, system.data, version=1.0.3300.0, culture=neutral, publickeytoken=b77a5c561934e089" />
<connectionstring value="server=localhost;database=demo;user id=sa;password=123456" />
<commandtext value="insert into log ([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>
</log4net>
</configuration>2,Application Start
protected void Application_Start(Object sender, EventArgs e)
{
log4net.Config.DOMConfigurator.Configure(); 
}
错误信息如下:
---------------------------
Microsoft Development Environment
---------------------------
A project with an Output Type of Class Library cannot be started directly.In order to debug this project, go to the Debugging tab under Configuration Settings in Project Properties, and set the Start Action to Start External Program or Start URL. Alternatively, you can add a non-library project to this solution that uses a reference to this project and set it as the startup project.帮忙看看,谢谢。在线等

解决方案 »

  1.   

    A project with an Output Type of Class Library cannot be started directly.In order to debug this project, go to the Debugging tab under Configuration Settings in Project Properties, and set the Start Action to Start External Program or Start URL. Alternatively, you can add a non-library project to this solution that uses a reference to this project and set it as the startup project.
      
      

  2.   

    换成这样试试..  <configSections>
        <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
      </configSections>
      

  3.   

    如果还是不行,将
    <log4net>
    ....
    </log4net>这一块放到前面,即:<configSections>
        <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
      </configSections>
    <log4net>
    ....
    </log4net>然后其他..
      

  4.   

    在gloabal.ascs中读取初始配置
    protected void Application_Start(Object sender, EventArgs e)
    {
    log4net.Config.XmlConfigurator.Configure ();
    }
      

  5.   

    在gloabal.asax.cs文件中定义
    protected static log4net.ILog log  = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    在Application_Start中写 
    log4net.Config.DOMConfigurator.Configure();
      

  6.   

    给你一个例子(用在webservice里的)web.config<?xml version="1.0"?>
    <!-- 
        注意: 除了手动编辑此文件以外,您还可以使用 
        Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
         “网站”->“Asp.Net 配置”选项。
        设置和注释的完整列表在 
        machine.config.comments 中,该文件通常位于 
        \Windows\Microsoft.Net\Framework\v2.x\Config 中
    -->
    <configuration>
      
      <configSections>
        <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
      </configSections>
      <log4net>
        
        <!--日志输出到文本文件中-->
        <appender name="RollingTxtFile" type="log4net.Appender.RollingFileAppender">
          <file value="Log.txt" />
          <appendToFile value="true" />
          <!--容量最大为3KB-->
          <maximumFileSize value="100KB" />
          <!--最大允许有两个备份文件-->
          <maxSizeRollBackups value="10" />      <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d %t - %message%newline" />
          </layout>
        </appender>    <root>
          <level value="ALL" />
          <appender-ref ref="RollingTxtFile" />
        </root>
      </log4net>
      
      
    <appSettings/>
    <connectionStrings/>
    <system.web>
    <!-- 
                设置 compilation debug="true" 将调试符号插入
                已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。
            -->
    <compilation debug="true"/>
    <!--
                通过 <authentication> 节可以配置 ASP.NET 使用的 
                安全身份验证模式,
                以标识传入的用户。 
            -->
    <authentication mode="Windows"/>
    <!--
                如果在执行请求的过程中出现未处理的错误,
                则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
                开发人员通过该节可以配置
                要显示的 html 错误页
                以代替错误堆栈跟踪。        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    </system.web>
    </configuration>
      

  7.   

    测试代码..using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using log4net;
    using log4net.Config;
    using System.IO;
    using System.Reflection;
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Service : System.Web.Services.WebService
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public Service()
        {
            string FilePath = Server.MapPath("Web.Config");
            XmlConfigurator.ConfigureAndWatch(new FileInfo(FilePath));
        }    [WebMethod ]
        public string HelloWorld() {
            log.Debug("HelloWord Begin...");
            log.Debug("HelloWord End...");
            return "HelloWord";
        } 
    }
      

  8.   

    To,liujia_0421(SnowLover)
    1. ALL
    2. DEBUG 
    3. INFO 
    4. WARN 
    5. ERROR
    6. FATAL
    7. OFF等级如何来配置,能详细解释一下吗
      

  9.   

    <root>
    <level value="ALL" />
    <appender-ref ref="RollingTxtFile" />
    </root>配置其中的level value一般就够了。如果有需要,log4net文档里面太详细了。