ASP.NET/MVC 配置log4net启用写错误日志功能

2016-12-30 09:55:41来源:oschina作者:深圳大道人点击

<?xml version="1.0" encoding="utf-8"?>












































































































































using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class LogHelper
{
public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
public static void WriteInfo(string info)
{
loginfo.Info(info);
}
public static void WriteError(string info, Exception ex)
{
logerror.Error(info, ex);
}
} using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WWW
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
LogHelper.WriteInfo(string.Format("当前的时间{0}", DateTime.Now.ToString()));
try
{
Convert.ToInt32("aaa");
}
catch (Exception ex)
{
LogHelper.WriteError(string.Format("当前的时间{0}", DateTime.Now.ToString()), ex);
}

}
}
}

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台