使用asp.net中的Enterprise Library实现日志文件
发布时间:2020-05-23 21:54:05 所属栏目:asp.Net 来源:互联网
导读:我在asp.net中使用Microsoft Enterprise Library 3.1进行异常处理,错误存储在系统的事件查看器中. 我需要使用Enterprise Library将这些错误存储在日志文件中,而不是事件查看器. 亲爱的2:30,您将以下代码粘贴在app.config或web.config文件的配置部分中 configS
|
我在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 – HttpError不会显示自定义错误页面
- ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
- asp.net – 会话变量保存在哪里?
- asp.net-mvc – Css和脚本不工作,直到用户登录网站 – Asp.
- asp.net-mvc – 带MVC结果的Response.Flush无效
- asp.net – 缓存viewstate?
- 如何在Asp.net中使用HSL
- StructureMap和ASP .Net Web API和.Net Framework 4.5
- asp.net-mvc – 如何使用MVC 4制作提交按钮
- “ASP.Net身份”如何与“Windows身份基金会”进行比较?
推荐文章
站长推荐
- asp.net-mvc – Asp.Net MVC中的管理区域
- asp.net-mvc – “GenerateResource”任务失败,意
- asp.net – System.InvalidOperationException:
- asp.net-mvc – asp.mvc视图在发布配置中引用#IF
- asp.net-mvc – VaryByParam =“*”是否也读取了
- asp.net-mvc – 如何重定向HTTP到HTTPS在MVC应用
- Asp.net静态可变生命周期刷新和PostBack
- 在asp.net按钮中添加图像和文本
- ASP.NET中的401.2的customerrors
- asp.net-mvc – ASP.NET MVC UpdateModel容易受到
热点阅读
