客户端类中中记录异常的方法: 使用Log4net

1、首先引用Log4Net 的命名空间

using log4net;

2、在使用的类中生命静态变量 log

public class FileService
    {
        static readonly ILog log = LogManager.GetLogger(typeof(FileService));

.....

.....

3、在 try catch 语句中记录异常信息

try
{
operationHandler(fileName);
return FileOperationResult.Successful;
}
catch (IOException ex)
{
log.Info("Unable to save file: " + fileName, ex);
userMessage = "A problem occured saving the file."; /* TODO: Make localizable resource. */
ioExceptionOccured = true;
}
catch (Exception ex) /* TODO: catch common IO errors and report to user. */
{
log.Info("Unable to save file: " + fileName, ex);
var userMessageException = ex as IUserMessageProvider;
if (userMessageException != null && userMessageException.UserMessagePresent)
{
userMessage = userMessageException.UserMessage;
}
}
上一篇:jq html 页面点击图片直接上传


下一篇:HBase与MongDB等NoSQL数据库对照