2016-02-23 82 views
0

我嘗試使用log4net登錄我的wep項目。使用EntityFramework和LINQ進行數據庫。我添加這些成的web.config文件如何使用Log4net進行日誌記錄?

<configSections> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 
</configSections> 

<log4net> 
    <logger name ="DBLogger"> 
     <level value="ALL"></level> 
     <appender-ref ref="AdoNetAppender" /> 
    </logger> 
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> 
     <bufferSize value="100" /> 
     <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <connectionString value="data source=localhost;initial catalog=CATALOG_NAME;persist security info=False;user id=DB_USER;password=DB_PASSWORD;MultipleActiveResultSets=True;App=EntityFramework" /> 

     <commandText value="INSERT INTO RCN_OPERATION_LOGS ([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 ip=%property{ip}" /> 
     </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> 



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

<appSettings> 
    <add key="log4net.Internal.Debug" value="true" /> 
    <add key="log4net.Config" value="log4net.config"/> 
    <add key="log4net.Config.Watch" value="True"/> 
</appSettings> 

添加此線分成的AssemblyInfo.cs:

[組件:log4net.Config.XmlConfigurator(通過ConfigFile = 「web.config中」,觀看=真)]

而且的Global.asax.cs:

protected void Application_Start(object sender, EventArgs e) 
    { 
     log4net.Config.XmlConfigurator.Configure(); 
    } 

我創建了一個這樣的Logger類;

Logger logger = new Logger(); 
logger.AddLog(oUser.USERNAME, "InfoFormat", "KullanıcıIslem", "Kullanıcı sisteme giriş yaptı.", null, null); 

但是,任何記錄添加到數據庫:當用戶登錄

using log4net; 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Reflection; 
using System.Text; 
using System.Threading.Tasks; 

namespace FITMutabakat.BLL.Base 
{ 
    public class Logger : Manager 
    { 
     private static readonly ILog logger = LogManager.GetLogger("DBLogger"); 

     public void AddLog(string user, string loggertype, string logprocess, string mesaj, string data, Exception ex) 
     { 
      LoggerAdd(logger, loggertype, logprocess, user, data, mesaj, ex); 
      this.Context.SaveChanges(); 
     } 


     public static void LoggerAdd(log4net.ILog logger, string LoggerType, string LogProcess, string User, string Data, string LogMessage, System.Exception Ex) 
     { 
      try 
      { 
       if (LoggerType == "InfoFormat") 
       { 
        object[] args = new object[4]; 
        logger.Info("sdf"); 

        if (Data != null) 
        { 
         args[0] = LogProcess; 
         args[1] = User; 
         args[2] = Data; 
         args[3] = LogMessage; 
         logger.InfoFormat("[{0}] [{1}] [{2}] [{3}]", args); 
        } 
        else 
        { 
         args[0] = LogProcess; 
         args[1] = User; 
         args[2] = LogMessage; 
         logger.InfoFormat("[{0}] [{1}] [{2}] ", args); 
        } 
       } 
       else if (LoggerType == "Fatal") 
       { 
        if (Data != null) 
        { 
         object[] args = new object[4]; 
         args[0] = LogProcess; 
         args[1] = User; 
         args[2] = Data; 
         args[3] = LogMessage; 
         string ermes = string.Format("[{0}] [{1}] [{2}] [{3}]", args); 
         logger.Fatal(ermes, Ex); 
        } 
        else 
        { 
         object[] args = new object[4]; 
         args[0] = LogProcess; 
         args[1] = User; 
         args[2] = LogMessage; 
         string ermes = string.Format("[{0}] [{1}] [{2}] ", args); 
         logger.Fatal(ermes, Ex); 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 
     } 
    } 
} 

Logger類被調用。問題在哪裏,我找不到。 當程序運行時,log4net將這些文件寫入調試文件,但得到任何錯誤。

log4net: log4net assembly [log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\Users\admin\AppData\Local\Temp\Temporary ASP.NET Files\vs\05d71218\bc109529\assembly\dl3\d1df1039\3eae6e67_6b57d101\log4net.dll]. (.NET Runtime [4.0.30319.34209] on Microsoft Windows NT 6.2.9200.0) 
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy] 
log4net: Creating repository for assembly [FITMutabakat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] 
log4net: Assembly [FITMutabakat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Users\admin\AppData\Local\Temp\Temporary ASP.NET Files\vs\05d71218\bc109529\assembly\dl3\a6a085ea\52e3a93b_3a6ed101\FITMutabakat.dll] 
log4net: Assembly [FITMutabakat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. 
log4net: Assembly [FITMutabakat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] 
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy] 
log4net: configuring repository [log4net-default-repository] using file [C:\HttpRoot\FITMutabakat\FITMutabakat\web.config] watching for file updates 
log4net: configuring repository [log4net-default-repository] using file [C:\HttpRoot\FITMutabakat\FITMutabakat\web.config] 
log4net: configuring repository [log4net-default-repository] using stream 
log4net: loading XML configuration 
log4net: Configuring Repository [log4net-default-repository] 
log4net: Configuration update mode [Merge]. 
log4net: Retrieving an instance of log4net.Repository.Logger for logger [DBLogger]. 
log4net: Setting [DBLogger] additivity to [True]. 
log4net: Logger [DBLogger] Level string is [ALL]. 
log4net: Logger [DBLogger] level set to [name="ALL",value=-2147483648]. 
log4net: Loading Appender [AdoNetAppender] type: [log4net.Appender.AdoNetAppender] 
log4net: Setting Property [BufferSize] to Int32 value [100] 
log4net: Setting Property [ConnectionType] to String value [System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089] 
log4net: Setting Property [ConnectionString] to String value [data source=localhost;initial catalog=MUTABAKAT_DEV;persist security info=False;user id=sa;password=369900;MultipleActiveResultSets=True;App=EntityFramework] 
log4net: Setting Property [CommandText] to String value [INSERT INTO RCN_OPERATION_LOGS ([DATE],[THREAD],[LEVEL],[LOGGER],[MESSAGE],[EXCEPTION]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)] 
log4net: Setting Property [ParameterName] to String value [@log_date] 
log4net: Setting Property [DbType] to DbType value [DateTime] 
log4net: Setting Property [Layout] to object [log4net.Layout.RawTimeStampLayout] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@thread] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%thread ip=%property{ip}] 
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [literal] Option [ ip=] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [property] Option [ip] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@log_level] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [50] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%level] 
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@logger] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%logger] 
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@message] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [4000] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%message] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@exception] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [2000] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Created Appender [AdoNetAppender] 
log4net: Adding appender named [AdoNetAppender] to logger [DBLogger]. 
log4net: Hierarchy Threshold [] 
log4net: Loading and watching configuration for default repository from AppSettings specified Config path [C:\HttpRoot\FITMutabakat\FITMutabakat\log4net.config] 
log4net: configuring repository [log4net-default-repository] using file [C:\HttpRoot\FITMutabakat\FITMutabakat\log4net.config] watching for file updates 
log4net: configuring repository [log4net-default-repository] using file [C:\HttpRoot\FITMutabakat\FITMutabakat\log4net.config] 
log4net: configuring repository [log4net-default-repository] using stream 
log4net: loading XML configuration 
log4net: Configuring Repository [log4net-default-repository] 
log4net: Configuration update mode [Merge]. 
log4net: Logger [root] Level string is [ALL]. 
log4net: Logger [root] level set to [name="ALL",value=-2147483648]. 
log4net: Loading Appender [AdoNetAppender] type: [log4net.Appender.AdoNetAppender] 
log4net: Setting Property [BufferSize] to Int32 value [100] 
log4net: Setting Property [ConnectionType] to String value [System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089] 
log4net: Setting Property [ConnectionString] to String value [data source=localhost;initial catalog=MUTABAKAT_DEV;persist security info=False;user id=sa;password=369900;MultipleActiveResultSets=True;App=EntityFramework] 
log4net: Setting Property [CommandText] to String value [INSERT INTO RCN_OPERATION_LOGS ([DATE],[THREAD],[LEVEL],[LOGGER],[MESSAGE],[EXCEPTION]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)] 
log4net: Setting Property [ParameterName] to String value [@log_date] 
log4net: Setting Property [DbType] to DbType value [DateTime] 
log4net: Setting Property [Layout] to object [log4net.Layout.RawTimeStampLayout] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@thread] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%thread ip=%property{ip}] 
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [literal] Option [ ip=] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [property] Option [ip] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@log_level] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [50] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%level] 
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@logger] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%logger] 
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@message] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [4000] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%message] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@exception] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [2000] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Created Appender [AdoNetAppender] 
log4net: Adding appender named [AdoNetAppender] to logger [root]. 
log4net: Hierarchy Threshold [] 
log4net: configuring repository [log4net-default-repository] using .config file section 
log4net: Application config file is [C:\HttpRoot\FITMutabakat\FITMutabakat\web.config] 
log4net: Configuring Repository [log4net-default-repository] 
log4net: Configuration update mode [Merge]. 
log4net: Retrieving an instance of log4net.Repository.Logger for logger [DBLogger]. 
log4net: Setting [DBLogger] additivity to [True]. 
log4net: Logger [DBLogger] Level string is [ALL]. 
log4net: Logger [DBLogger] level set to [name="ALL",value=-2147483648]. 
log4net: Loading Appender [AdoNetAppender] type: [log4net.Appender.AdoNetAppender] 
log4net: Setting Property [BufferSize] to Int32 value [100] 
log4net: Setting Property [ConnectionType] to String value [System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089] 
log4net: Setting Property [ConnectionString] to String value [data source=localhost;initial catalog=MUTABAKAT_DEV;persist security info=False;user id=sa;password=369900;MultipleActiveResultSets=True;App=EntityFramework] 
log4net: Setting Property [CommandText] to String value [INSERT INTO RCN_OPERATION_LOGS ([DATE],[THREAD],[LEVEL],[LOGGER],[MESSAGE],[EXCEPTION]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)] 
log4net: Setting Property [ParameterName] to String value [@log_date] 
log4net: Setting Property [DbType] to DbType value [DateTime] 
log4net: Setting Property [Layout] to object [log4net.Layout.RawTimeStampLayout] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@thread] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%thread ip=%property{ip}] 
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [literal] Option [ ip=] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [property] Option [ip] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@log_level] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [50] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%level] 
log4net: Converter [level] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@logger] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [255] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%logger] 
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@message] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [4000] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [ConversionPattern] to String value [%message] 
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Setting Property [ParameterName] to String value [@exception] 
log4net: Setting Property [DbType] to DbType value [String] 
log4net: Setting Property [Size] to Int32 value [2000] 
log4net: Setting Property [Layout] to object [log4net.Layout.Layout2RawLayoutAdapter] 
log4net: Setting Collection Property [AddParameter] to object [log4net.Appender.AdoNetAppenderParameter] 
log4net: Created Appender [AdoNetAppender] 
log4net: Adding appender named [AdoNetAppender] to logger [DBLogger]. 
log4net: Hierarchy Threshold [] 
log4net: Creating repository for assembly [FITMutabakat.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] 
log4net: Assembly [FITMutabakat.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Users\admin\AppData\Local\Temp\Temporary ASP.NET Files\vs\05d71218\bc109529\assembly\dl3\4f082a23\1998a73a_3a6ed101\FITMutabakat.BLL.dll] 
log4net: Assembly [FITMutabakat.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified. 
log4net: Assembly [FITMutabakat.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy] 
log4net: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy] 
+1

您的帖子太短。 –

+0

看着這個。最好的log4net tuttorial我找到了。 https://www.youtube.com/watch?v=2lAdQ_QwNww – Jacobr365

+0

您的數據庫密碼位於log4net輸出中。 – stuartd

回答

1

有幾件事我可以看出哪些可能會丟失,可能是您的記錄器不工作的原因。

首先,在Global.asax.cs中的文件我也有:

private static readonly ILog log = LogManager.GetLogger(typeof(MvcApplication)); 

    void Application_Error(Object sender, EventArgs e) 
    { 
     Exception ex = Server.GetLastError().GetBaseException(); 
     log.Error("App_Error", ex); 
    } 

    protected void Application_Start() 
    { 
     log4net.Config.XmlConfigurator.Configure(); 
    } 

然後在web.config文件中也看不出你有任何地方log4net的標籤內的<root>標籤。它看起來像你試圖做到這一點<logger>,我不知道這是從哪裏。另外,我會將緩衝區大小從100更改爲1(而不是等待100寫入數據庫之前寫入每個日誌)。我會將整個部分更改爲:

<configSections> 
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 
</configSections> 
<log4net debug="true"> 
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> 
    <bufferSize value="1" /> 
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    <connectionString value="data source=localhost;initial catalog=CATALOG_NAME;persist security info=False;user id=DB_USER;password=DB_PASSWORD;MultipleActiveResultSets=True;App=EntityFramework" /> 

    <commandText value="INSERT INTO RCN_OPERATION_LOGS ([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 ip=%property{ip}" /> 
    </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>