zoukankan      html  css  js  c++  java
  • 客户端类中中记录异常的方法: 使用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;
    				}
    			}
    

         

  • 相关阅读:
    input 蓝边
    4.【ac自动机】模式串匹配
    3.【二叉树】最近公共祖先
    2.【动态规划】最长回文子串
    1. 【线段树】
    DbUtil
    oauth2
    cas
    Spring-security-web
    JSON Web Tokens
  • 原文地址:https://www.cnblogs.com/babietongtianta/p/3522230.html
Copyright © 2011-2022 走看看