您的位置:程序门 -> .net技术 -> c#



程序中用了log4net,就不能启动。显示信息如下,大家看看


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


程序中用了log4net,就不能启动。显示信息如下,大家看看[已结贴,结贴人:echoxue]
发表于:2007-01-31 00:22:55 楼主
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.

帮忙看看,谢谢。在线等
发表于:2007-01-31 01:02:571楼 得分:2
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.
   

发表于:2007-01-31 01:03:042楼 得分:2
详细看看
   

发表于:2007-01-31 09:49:273楼 得分:2
换成这样试试..

    <configsections>
        <section   name= "log4net "   type= "system.configuration.ignoresectionhandler "   />
    </configsections>

发表于:2007-01-31 09:51:334楼 得分:2
如果还是不行,将
<log4net>
....
</log4net>

这一块放到前面,即:

<configsections>
        <section   name= "log4net "   type= "system.configuration.ignoresectionhandler "   />
    </configsections>
<log4net>
....
</log4net>

然后其他..
发表于:2007-01-31 09:52:365楼 得分:2
以上不能肯定,仅供参考...

发表于:2007-01-31 12:27:366楼 得分:2
在gloabal.ascs中读取初始配置
protected   void   application_start(object   sender,   eventargs   e)
{
log4net.config.xmlconfigurator.configure   ();
}
发表于:2007-01-31 12:28:557楼 得分:2
gloabal.asax.cs
发表于:2007-01-31 13:33:218楼 得分:2
在gloabal.asax.cs文件中定义
protected   static   log4net.ilog   log     =   log4net.logmanager.getlogger(system.reflection.methodbase.getcurrentmethod().declaringtype);
在application_start中写  
log4net.config.domconfigurator.configure();
发表于:2007-02-01 00:22:319楼 得分:0
抱歉大家,公司不能上网,只能回来回复,那位有详细的例子我参考一下
不想去看源代码了。太费时间了。

谢谢
发表于:2007-02-01 08:47:5410楼 得分:3
给你一个例子(用在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>
发表于:2007-02-01 08:50:0311楼 得分:0
测试代码..

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 ";
        }  
}
发表于:2007-02-02 00:34:0012楼 得分:0
to,liujia_0421(snowlover)
1.   all
2.   debug  
3.   info  
4.   warn  
5.   error
6.   fatal
7.   off

等级如何来配置,能详细解释一下吗
发表于:2007-02-02 13:32:4213楼 得分:1
<root>
<level   value= "all "   />
<appender-ref   ref= "rollingtxtfile "   />
</root>

配置其中的level   value一般就够了。如果有需要,log4net文档里面太详细了。
发表于:2007-02-02 14:36:2114楼 得分:0
同:   lextm(lele)


快速检索

最新资讯
热门点击