• log4net 日志跟踪


    1,web.config文件里加:
    (1)<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
    (2)<log4net>
      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
       <file value="./QuotationLog.txt"/>
       <!-- Example using environment variables in params -->
       <!-- <file value="${TMP}\log-file.txt" /> -->
       <!--<sppendToFile value="true" />-->
       <!-- An alternate output encoding can be specified -->
       <!-- <encoding value="unicodeFFFE" /> -->
       <layout type="log4net.Layout.PatternLayout">
        <footer value="[Footer]--Sean &#xA;"/>
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline"/>
       </layout>
       <!-- Alternate layout using XML  
       <layout type="log4net.Layout.XMLLayout" /> -->
      </appender>
      <!-- Setup the root category, add the appenders and set the default level -->
      <root>
       <appender-ref ref="LogFileAppender"/>
      </root>
    </log4net>
    <appSettings>
    /*************************/
    <?xml version="1.0"?>
    <!--
        Note: As an alternative to hand editing this file you can use the
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in
        machine.config.comments usually located in
        \Windows\Microsoft.Net\Framework\v2.x\Config
    -->
    <configuration>
    <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
       <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
         <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
         <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
         <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
         <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
       </sectionGroup>
      </sectionGroup>
      <!-- Orm Setting-->
      <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
      <section name="BuildingSetting" type="Xingon.Db.Configuration.BuilderSection,Xingon.Db"/>
      <section name="magicAjax" type="MagicAjax.Configuration.MagicAjaxSectionHandler, MagicAjax"/>
      <!--log4net config-->
    </configSections>
    <!-- This section contains the log4net configuration settings -->
    <log4net>
      <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
       <file value="./QuotationLog.txt"/>
       <!-- Example using environment variables in params -->
       <!-- <file value="${TMP}\log-file.txt" /> -->
       <!--<sppendToFile value="true" />-->
       <!-- An alternate output encoding can be specified -->
       <!-- <encoding value="unicodeFFFE" /> -->
       <layout type="log4net.Layout.PatternLayout">
        <footer value="[Footer]--Sean &#xA;"/>
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; - %message%newline"/>
       </layout>
       <!-- Alternate layout using XML  
       <layout type="log4net.Layout.XMLLayout" /> -->
      </appender>
      <!-- Setup the root category, add the appenders and set the default level -->
      <root>
       <appender-ref ref="LogFileAppender"/>
      </root>
    </log4net>
    <appSettings>
      <add key="LoginUrl" value="http://localhost:7684/AdChina.Web/Home/Login.aspx"></add>
      <add key="AuthorityUrl" value="http://localhost:7684/AdChina.Web/Home/Home.aspx"></add>
      <add key="IsSuperAdmin" value="1"></add>
      <add key="QuotationFilePath" value="../QuotationFile"></add>
      <!--是否打开超级管理员,1为打开 0为不打开,如果打开下面SuperAdmin的人可以操作系统任何动作 请谨慎开启-->
      <add key="SuperAdmin" value="mao,yu,fa"></add>
      <add key="LogPath" value="D:\"/>
      <add key="LogOn" value="false"/>
    </appSettings>
    <!-- Orm or database detail-->
    <connectionStrings>
      <add name="adchina" connectionString="Data Source=adchina;Persist Security Info=True;User ID=adchina_user;Password=adchinadb;pooling=true;Max Pool Size=2;" providerName="System.Data.OracleClient"/>
        <add name="ConnectionString" connectionString= "Data Source=adchina;Persist Security Info=True;User ID=ac_corp;Password=ac_corp;Unicode=True;Pooling=true;Min Pool Size=1;Max Pool Size=2" providerName="System.Data.OracleClient"/>
      </connectionStrings>
    <!-- Orm  setting builder provider-->
    <BuildingSetting defaultProvider="OrcaleBuilder">
      <providers>
       <add name="OrcaleBuilder" type=" Xingon.Db.Provider.Oracle.BuildingProvider,Xingon.Db.Provider.Oracle"></add>
      </providers>
    </BuildingSetting>
    <system.web>
      <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
      <compilation debug="true">
       <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/></assemblies>
      </compilation>
      <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
      <authentication mode="Forms">
       <forms loginUrl="Home/Login.aspx" name=".ASPXAUTH" protection="All" timeout="20"/>
      </authentication>
      <authorization>
       <deny users="?"/>
      </authorization>
      <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.
      -->
      <customErrors mode="Off" defaultRedirect="error.aspx">
       <error statusCode="403" redirect="NoAccess.htm"/>
       <error statusCode="404" redirect="FileNotFound.htm"/>
      </customErrors>
      <pages>
       <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       </controls>
      </pages>
      <httpHandlers>
       <remove path="*.asmx" verb="*"/>
       <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
       <add path="*_AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
       <add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
       <add path="*/coolite.axd" verb="*" type="Coolite.Ext.Web.ResourceManager" validate="false"/>
      </httpHandlers>
      <httpModules>
       <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add name="MagicAjaxModule" type="MagicAjax.MagicAjaxModule, MagicAjax"/>
       <add name="AjaxRequestModule" type="Coolite.Ext.Web.AjaxRequestModule, Coolite.Ext.Web"/>
      </httpModules>
      <globalization uiCulture="zh-CN" culture="zh-CN"/>
    </system.web>
    <system.codedom>
      <compilers>
       <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
       </compiler>
       <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="OptionInfer" value="true"/>
        <providerOption name="WarnAsError" value="false"/>
       </compiler>
      </compilers>
    </system.codedom>
    <!--
            The system.webServer section is required for running ASP.NET AJAX under Internet
            Information Services 7.0.  It is not necessary for previous version of IIS.
        -->
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
       <remove name="ScriptModule"/>
       <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
       <remove name="WebServiceHandlerFactory-Integrated"/>
       <remove name="ScriptHandlerFactory"/>
       <remove name="ScriptHandlerFactoryAppServices"/>
       <remove name="ScriptResource"/>
       <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </handlers>
    </system.webServer>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
       </dependentAssembly>
       <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
       </dependentAssembly>
      </assemblyBinding>
    </runtime>
    <system.serviceModel>
      <behaviors>
       <endpointBehaviors>
        <behavior name="BtnActionAspNetAjaxBehavior">
         <enableWebScript/>
        </behavior>
        <behavior name="AcSortAspNetAjaxBehavior">
         <enableWebScript/>
        </behavior>
       </endpointBehaviors>
      </behaviors>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
      <services>
       <service name="BtnAction">
        <endpoint address="" behaviorConfiguration="BtnActionAspNetAjaxBehavior" binding="webHttpBinding" contract="BtnAction"/>
       </service>
       <service name="AcSort">
        <endpoint address="" behaviorConfiguration="AcSortAspNetAjaxBehavior" binding="webHttpBinding" contract="AcSort"/>
       </service>
      </services>
    </system.serviceModel>
    <location path="Js">
      <system.web>
       <authorization>
        <allow users="*"/>
       </authorization>
      </system.web>
    </location>
    <location path="Theme">
      <system.web>
       <authorization>
        <allow users="*"/>
       </authorization>
      </system.web>
    </location>
    </configuration>

    2,
        在Web项目的 Properties 目录下的 AssemblyInfo.cs 里加上:
    [assembly: log4net.Config.XmlConfigurator(Watch = true)]

       //3,
       //加一个log全局变量:
        //private static readonly log4net.ILog log = log4net.LogManager.GetLogger 

        //(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

     3, 在每个页面的后台代码里加:

    private static readonly ILog log = LogManager.GetLogger(typeof(页面类名));

  • 相关阅读:
    spring boot + activeMq 邮件服务
    spring boot集成activeMQ
    Java做爬虫也很方便
    Go语言学习03
    MongoDB学习-->Gridfs分布式存储&DBRef关联查询
    tomcat与oracle关于8080端口的冲突
    端口号的查找处理方法
    很不错的在线Office控件:IWebOffice与SOAOffice
    SOAOffice和iWebOffice、NTKO的比较及其优势(转)
    Cannot get a connection, pool exhausted解决办法
  • 原文地址:https://www.cnblogs.com/MySpace/p/1599681.html
Copyright © 2020-2023  润新知