简体   繁体   中英

How do I remove ellipses from a stack trace in C#?

I am trying to log a stack trace to SQL Server in C#. Occasionally, I get a stack trace like this one:

System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.) (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.) ----> System.ComponentModel.Win32Exception: The wait operation timed out --- End of inner ExceptionDetail stack trace --- at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String ne wPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderMa...).

Notice the.. after SqlInternalConnectionTds and the... after SqlAuthenticationProviderMa. I'm not adding in the ellipses. How do I get rid of this truncated text and get the FULL exception?

Thanks!

Best way to get a full stack trace is usually just to call ToString()

For example in MVC: File:

/Shared/Error.cshtml

Code:

@model System.Web.Mvc.HandleErrorInfo
<pre>
     @Model.Exception.ToString()
</pre>

I found the solution. This issue only happens on FaultException objects. I called the stack trace explicitly, and logged it. Using this method, everything works fine.

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