使用asp.net中的Enterprise Library实现日志文件
发布时间:2020-12-16 00:07:00 所属栏目:asp.Net 来源:网络整理
导读:我在asp.net中使用Microsoft Enterprise Library 3.1进行异常处理,错误存储在系统的事件查看器中. 我需要使用Enterprise Library将这些错误存储在日志文件中,而不是事件查看器. 解决方法 亲爱的2:30,您将以下代码粘贴在app.config或web.config文件的配置部分
我在asp.net中使用Microsoft Enterprise Library 3.1进行异常处理,错误存储在系统的事件查看器中.
我需要使用Enterprise Library将这些错误存储在日志文件中,而不是事件查看器. 解决方法
亲爱的2:30,您将以下代码粘贴在app.config或web.config文件的配置部分中
<configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,Microsoft.Practices.EnterpriseLibrary.Logging,Version=3.1.0.0,Culture=neutral,PublicKeyToken=null" /> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary.Data,PublicKeyToken=null" /> </configSections> <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Tracing" logWarningsWhenNoCategoriesMatch="true"> <listeners> <add fileName="AppLog.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData,PublicKeyToken=null" traceOutputOptions="LogicalOperationStack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,PublicKeyToken=null" name="AppLog" /> <add fileName="Exception.log" rollSizeKB="1024" timeStampPattern="MM-dd-yyyy" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData,PublicKeyToken=null" traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,PublicKeyToken=null" name="Exception" /> <add fileName="trace.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Month" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData,PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,PublicKeyToken=null" name="Trace" /> </listeners> <formatters> <add template="{timestamp} : {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,PublicKeyToken=null" name="Text Formatter" /> </formatters> <categorySources> <add switchValue="All" name="AppLog"> <listeners> <add name="AppLog" /> </listeners> </add> <add switchValue="Verbose" name="ExceptionHandling"> <listeners> <add name="Exception" /> </listeners> </add> <add switchValue="Information" name="Tracing"> <listeners> <add name="Trace" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events" /> <notProcessed switchValue="All" name="Unprocessed Category" /> <errors switchValue="Off" name="Logging Errors & Warnings" /> </specialSources> </loggingConfiguration> 可以使用以下语句将应用程序日志记录到applog.log文件中 Logger.Write("Application Started","AppLog"); 可以使用以下语句将应用程序异常记录到Exception.log文件中 Logger.Write("Error: Invalid information you passed","ExceptionHandling"); 注意:您可以在Microsoft.Practices.EnterpriseLibrary.Logging中找到Logger类; AppLog.log和Exception.log文件将自动在bin文件夹中创建. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 用于ASP的Telerik扩展. NET MVC免费?
- asp.net-web-api – 如何设置katana-project以允许json格式
- 详细介绍有关于.NET的委托
- asp.net-core-signalr – SignalR Core中的SendAsync和Send
- ASP.NET C# 实现钉钉签名算法
- 谈谈基于SQL Server 的Exception Handling[中篇]
- asp.net-mvc – 可以通过RedirectToAction传递模型吗?
- asp.net – 在MVC中控制SQL注入
- asp.net – 如何将流excel文件转换为数据表C#?
- 实体框架 – 为什么没有[Authorize(Roles =“Admin”)]在具
推荐文章
站长推荐
- 检测到在集成的托管管道模式下不适用的ASP.NET设
- asp.net – 我如何计算出我的服务器可以处理的最
- asp.net – 为什么无法使用ID“Server”进行控制
- asp.net-mvc-5 – OWIN和IIS集成的内部
- asp.net – 使用MVC 4的.NET 4.5数据访问应用程序
- asp.net – Visual Studio 2005:是否有一个简单
- asp.net – 在Azure部署期间(彻底改变)Web.confi
- asp.net – AJAX updatepanel给出错误
- 内存数据库之Apache Ingite
- 像ASP.NET WebControls一样,在dll中可重用的ASP.
热点阅读