110,534
社区成员
发帖
与我相关
我的任务
分享
public class GlobalExceptionHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
FileStream aFile = new FileStream(@"C:\Data\Log.txt", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine("时间:{0}" + System.Environment.NewLine + "错误:{1}", System.DateTime.Now.ToString("MM-dd HH:mm:ss.fff"), error.Message);
sw.Close();
}
[GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler))]
public class BizService : IContract
这样做,可以捕获Exption异常,但OutOfMemoryException服务器程序还是挂掉.
有人解释一下吗?
static void Main(string[] args)
{
Console.Title = "应用服务";
bool flag = true;
string cmd = "";
using (ServiceHost host = new ServiceHost(typeof(BizService)))
{
DateTime dtNow = DateTime.Now;
host.Opened += delegate
{
Console.WriteLine("启动时间:" + dtNow);
Console.WriteLine("BizService服务启动 ......");
Console.Write(">");
};
host.Open();
while (flag == true)
{
cmd = Console.ReadLine().Trim();
switch (cmd)
{
case "exit":
flag = false;
break;
case "cls":
Console.Clear();
Console.WriteLine("启动时间:" + dtNow);
Console.WriteLine("BizService服务启动 ......");
Console.Write(">");
break;
case "call":
Console.WriteLine("执行call");
Console.Write(">");
break;
}
}
}
}
public class BizService : IContract
{
public DataTable GetXxByID(string ID)
{
//throw new OutOfMemoryException("内存溢出.........");///这里为人为抛出异常.服务就会挂掉
return l_Rule.GetXxByID(ID);
}
.........
}
GetXxByID 这样的方法很多,现在不知道哪个方法报异常引起的问题.