Log Management (log4net) encapsulate System Log build dll

Source: Internet
Author: User
Tags log4net

Namespace MyLog4net
{
Public static class Mylog4net
{
Public enum ErrorLogType
{
/// <Summary>
/// Fatal error log
/// </Summary>
FatalLog,
/// <Summary>
/// Error Log
/// </Summary>
ErrorLog
}

/// <Summary>
/// When a prompt is required, you must specify the log type, which is generally used when the system prompts you how to operate,
/// This type should be used for even warning operations
/// </Summary>
Public enum NormalLogType
{
/// <Summary>
/// Common operation log
/// </Summary>
InfoLog,
/// <Summary>
/// Warning log
/// </Summary>
WarnLog,
/// <Summary>
/// Debug log
/// </Summary>
DebugLog
}
/// <Summary>
/// System Operation Log (info, warm)
/// </Summary>
/// <Param name = "modelClassName"> name of the operation class, </param>
/// <Param name = "functionName"> function name </param>
/// <Param name = "strInfo"> log information. </Param>
/// <Param name = "logtype"> log level </param>
Public static void Write (string modelClassName, string functionName, string strInfo, NormalLogType logtype)
{
Log4net. ILog log = log4net. LogManager. GetLogger (modelClassName + "." + functionName );
Switch (logtype)
{
Case NormalLogType. DebugLog:
Log. Debug (strInfo );
Break;
Case NormalLogType. InfoLog:
Log. Info (strInfo );
Break;
Case NormalLogType. WarnLog:
Log. Warn (strInfo );
Break;

}

}
/// <Summary>
/// Write system operation logs, which are generally used for Error and Fatal
/// </Summary>
/// <Param name = "modelClassName"> Create an operation class name </param>
/// <Param name = "functionName"> function name: click, register </param>
/// <Param name = "errorMsg"> error message </param>
/// <Param name = "ex"> exception </param>
/// <Param name = "logtype"> error level </param>
Public static void Write (string modelClassName, string functionName, string errorMsg, Exception ex, ErrorLogType logtype)
{
Log4net. ILog log = log4net. LogManager. GetLogger (modelClassName + "." + functionName );
Switch (logtype)
{
Case ErrorLogType. ErrorLog:
Log. Error (errorMsg, ex );
Break;
Case ErrorLogType. FatalLog:
Log. Fatal (errorMsg, ex );
Break;

}

}

}
}

If % r is used, the correct class cannot be obtained. Seek discussion from friends!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.