简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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