问题描述:

I have the following code, I don't know this Log belongs to which namespace. Here is my code

catch (Exception ex)

{

Log.Error(" Error In Stored Procedure " + ex.Message + " " + individualid, ex);

}

网友答案:

Get Latest Package of Log4net using nuget Package Manager.

PM> Install-Package log4net 

Then

Add following section in Web.config

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

<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="C:\\TestProj\\TestLog.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="10MB" />
    <staticLogFileName value="true" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
    </layout>
</appender>

<root>
    <level value="DEBUG" />
    <appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>

Use following namespace in your code

using log4net;
using log4net.Config;

Call ILogger for your class

  private static readonly ILog logger = 
       LogManager.GetLogger(typeof(LogTemp));

LogTemp is your class file.

You can use Log by this way.

    logger.Debug("");
    logger.Info("");
    logger.Warn("");
    logger.Error("");
    logger.Fatal("");
相关阅读:
Top