net输出错误日志
在使用net开发webapi的时候,有时候程序异常了,外面只能看到一个错误:an error occur
怎么才能将具体的 错误堆栈信息输出来呢?
1.在startup.cs文件中添加如下代码就可以将错误信息输出:
GlobalConfiguration.Configure(c => c.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always);
代码如下:

2.Global.asax中捕获api错误信息:
protected void Application_Error(object sender, EventArgs e)
{
#region Error Log
var exp = HttpContext.Current.Server.GetLastError();
var sbErrorMsg = new StringBuilder();
sbErrorMsg.Append(DateTime.Now);
sbErrorMsg.Append(" 发生一个系统错误,如下:");
sbErrorMsg.Append("\r\n");
sbErrorMsg.Append("--------------------------------------------------------------------------------");
sbErrorMsg.Append("\r\n");
sbErrorMsg.Append("客户机IP:");
sbErrorMsg.Append(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
sbErrorMsg.Append("\r\n错误地址:");
sbErrorMsg.Append(Request.Url);
sbErrorMsg.Append("\r\n上一个URL:");
sbErrorMsg.Append((Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : ""));
sbErrorMsg.Append("\r\n");
var error = Common.ExceptionHelper.GetError(sbErrorMsg.ToString(), exp);
Console.WriteLine(error);
#endregion
}

net输出错误日志的更多相关文章
- Spring MVC自定义统一异常处理类,并且在控制台中输出错误日志
在使用SimpleMappingExceptionResolver实现统一异常处理后(参考Spring MVC的异常统一处理方法), 发现出现异常时,log4j无法在控制台输出错误日志.因此需要自定义 ...
- web端log4net输出错误日志到mysql
1.引用log4net 2.配置log4net.config文件 <?xml version="1.0" encoding="utf-8" ?> & ...
- 【夯实PHP基础】nginx php-fpm 输出php错误日志
本文地址 原文地址 分享提纲: 1.概述 2.解决办法(解决nginx下php-fpm不记录php错误日志) 1. 概述 nginx是一个web服务器,因此nginx的access日志只有对访问页面的 ...
- nginx php-fpm 输出php错误日志
nginx是一个web服务器,因此nginx的access日志只有对访问页面的记录,不会有php 的 error log信息. nginx把对php的请求发给php-fpm fastcgi进程来处理, ...
- 关于NGINX下开启PHP-FPM 输出PHP错误日志的设置(已解决)
最近在本地搭建的LNMP的开发环境.为了开发的时候不影响前端的正常开发就屏蔽的PHP里面php.ini中的一些错误提示.但是这样一来,就影响到了后端开发的一些问题比如不能及时调试开发中的一些问题. n ...
- nginx php-fpm 输出php错误日志(转)
nginx是一个web服务器,因此nginx的access日志只有对访问页面的记录,不会有php 的 error log信息. nginx把对php的请求发给php-fpm fastcgi进程来处理, ...
- SQL Server自动化运维系列——监控磁盘剩余空间及SQL Server错误日志(Power Shell)
需求描述 在我们的生产环境中,大部分情况下需要有自己的运维体制,包括自己健康状态的检测等.如果发生异常,需要提前预警的,通知形式一般为发邮件告知. 在所有的自检流程中最基础的一个就是磁盘剩余空间检测. ...
- C# 记录错误日志
程序的错误日志如何记录下来? 可以在遇到异常时,Catch异常,然后把异常的信息输出到txt文件中即可 /// <summary> /// 错误日志 /// </summary> ...
- nginx error_log 错误日志配置说明
nginx的error_log类型如下(从左到右:debug最详细 crit最少): [ debug | info | notice | warn | error | crit ] 例如:error_ ...
随机推荐
- 020.Dockerfile
docker-cli读取Dockerfile,根据指令生成定制的docker镜像. Dockerfile的指令根据作用可以分为两种,构建指令和设置指令. 构建指令:用于构建image,其指定的操作不会 ...
- SQLServer常用快捷键汇总
菜单激活键盘快捷键 操作 SQL Server 2017 SQL Server 2008 R2 移到 SQL Server Management Studio 菜单栏 Alt Alt 激活工具组件的菜 ...
- Alpha版本1
这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/2019autumnsystemanalysisanddesign/ 这个作业要求在哪里 https:// ...
- Apex 中 DML 进阶知识小结
DML 选项 在 DML 语句执行的时候可以设置选项.这些选项用 DML.Options 类来表示. 完整的介绍在官方文档中. 在建立一个 DML.Options 实例之后,可以使用 setOptio ...
- 在springboot中使用redis缓存,将缓存序列化为json格式的数据
背景 在springboot中使用redis缓存结合spring缓存注解,当缓存成功后使用gui界面查看redis中的数据 原因 springboot缓存默认的序列化是jdk提供的 Serializa ...
- polynote 安装试用
polynote 是netflix 开源的一个notebook 工具(支持scala,python,sql ...) 下载安装包 https://github.com/polynote/polynot ...
- Linux性能优化实战学习笔记:第二十五讲
一.磁盘性能指标 1.使用率 2.饱和度 3.IOPS 4.吞吐量 5.响应时间 6.性能测试工具 二.磁盘I/O观测 1.每块磁盘的使用率(指标实际上来自/proc/diskstats) [root ...
- [LeetCode] 827. Making A Large Island 建造一个巨大岛屿
In a 2D grid of 0s and 1s, we change at most one 0 to a 1. After, what is the size of the largest is ...
- [LeetCode] 843. Guess the Word 猜单词
This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...
- sqlserver数据库使用navicat生成数据字典
https://blog.csdn.net/Honnyee/article/details/86156832 SELECT 表名 then d.name else '' end, 表说明 then i ...