c# – 使用记录器记录堆栈跟踪
发布时间:2020-12-15 21:10:39 所属栏目:百科 来源:网络整理
导读:我正在使用带有C#.Net 2.0的Logging Application块.我的代码将错误信??息记录到平面文件中.我已经在web.config中设置了所有必需的配置,如监听器,格式化程序和类别等,如msdn中所述,它工作正常. 但问题是,我不能在le.Message属性中放置超过50个字符.在我的情况
我正在使用带有C#.Net 2.0的Logging Application块.我的代码将错误信??息记录到平面文件中.我已经在web.config中设置了所有必需的配置,如监听器,格式化程序和类别等,如msdn中所述,它工作正常.
但问题是,我不能在le.Message属性中放置超过50个字符.在我的情况下,堆栈跟踪超过500个字符长,我想在发生错误时登录到平面文件. 我们可以在LogEntry对象的Message Property中放置的charactors数量有限制吗?或者有没有其他方法将堆栈跟踪记录到logger平面文件中? 这是简单的代码. LogEntry le = new LogEntry(); le.Categories.Add("ErrorsToEventLog"); le.Categories.Add("ErrorsToLogFile"); le.Title = "Error message"; le.TimeStamp = System.DateTime.Now; le.Severity = System.Diagnostics.TraceEventType.Error; le.Message = "<text of error's stack trace>"; Logger.write(le); 配置设置 <configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,Microsoft.Practices.EnterpriseLibrary.Logging,Version=4.1.0.0,Culture=neutral,PublicKeyToken=null" /> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary.Data,PublicKeyToken=null" /> </configSections> 这是我使用的格式化程序, <formatters> <add template="Timestamp: {timestamp} Message: {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,PublicKeyToken=null" name="Text Formatter" /> </formatters> 这是听众, <add fileName="Logs/ErrorLog_{Date}.log" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration. CustomTraceListenerData,PublicKeyToken=null" traceOutputOptions="None" type="EnterpriseLibrary.Logging.Extensions.RollingFlatFileTraceListener,EnterpriseLibrary.Logging.Extensions,Version=1.0.0.0,PublicKeyToken=null" name="Custom TraceListener" initializeData="" /> 分类 <categorySources> <add switchValue="All" name="ErrorsToEventLog"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </add> <add switchValue="All" name="ErrorsToLogFile"> <listeners> <add name="Custom TraceListener" /> </listeners> </add> </categorySources> 解决方法
据我所知,日志消息没有这样的限制.如何将堆栈跟踪设置为消息?
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |