Sam Sippe
Sam Sippe

Reputation: 3190

How to prevent truncation of service exception in event log

We have a c# 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 "...".

Upvotes: 5

Views: 1540

Answers (1)

Yasser Shaikh
Yasser Shaikh

Reputation: 47794

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.

Upvotes: 0

Related Questions