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!