简体   繁体   English

如何防止在事件日志中截断服务异常

[英]How to prevent truncation of service exception in event log

We have ac# windows service that is failing which causes an error log message to be written to the windows event log. 我们有ac #windows服务失败,导致将错误日志消息写入Windows事件日志。 The error message contains the exception information but it is truncated, preventing us from seeing the critical information. 错误消息包含异常信息,但它被截断,阻止我们查看关键信息。

How do we increase the data that is written to the log message so we can see the full stacktrace of the exception? 我们如何增加写入日志消息的数据,以便我们可以看到异常的完整堆栈跟踪?

This is what we currently see in the event viewer. 这是我们目前在事件查看器中看到的内容。

<EventData>
    <Data>Service cannot be started. System.ArgumentException: Keyword not supported: 'port'. 
 at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) 
 at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) 
 at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) 
 at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) 
 at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) 
 at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<SetConnectionString>b__1a(DbConnection t...</Data> 
    </EventData>
</Event>

Note the end of the stacktrace is truncated with "...". 请注意,堆栈跟踪的末尾被截断为“...”。

You cannot increase the event log message size, if you are trying to write longer messages you should be getting an exception instead. 您无法增加事件日志消息大小,如果您尝试编写更长的消息,则应该获得异常。

MSDN says if you try to log message longer than the maximum limit which is 31,839 bytes (32,766 bytes on Windows operating systems before Windows Vista) ArgumentException is thrown. MSDN说,如果您尝试将消息记录的时间超过31,839字节的最大限制(在Windows Vista之前的Windows操作系统上为32,766字节),则抛出ArgumentException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM