Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mailing myself the trace information

Posted on 2014-02-10
9
Medium Priority
?
238 Views
Last Modified: 2014-02-12
When an exception is thrown I mail myself the exception data, logged in user, ip address, stuff like that.

I'd like to mail the trace information. Is there a way to retrieve that as a string to mail it?

thanks!
0
Comment
Question by:Starr Duskk
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 400 total points
ID: 39849467
Call ToString on your exception object.

Try
    'Your Code
Catch ex As Exception
    Debug.Writeline(ex.ToString)
End Try
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39849571
your better off sending it as an attachment
0
 
LVL 10

Expert Comment

by:John Claes
ID: 39850676
the exception has a stacktrace attribute you can use.
you can retreive the exception using try - catch
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 2

Author Comment

by:Starr Duskk
ID: 39850792
I must be missing something. I don't see an answer I can use in any of the responses.
0
 
LVL 40
ID: 39850954
You said that you mail yourself information, so I assumed that you knew how to send mail from your application.

All you have to add to get the trace is to had the result of ex.ToString in your Try...Catch...End Try.
0
 
LVL 13

Accepted Solution

by:
ktaczala earned 1600 total points
ID: 39850958
Write to a trace log, by default it will be here: My.Application.Info.DirectoryPath

Then in your script to build your mail message add this:
Dim attfile As New Attachment(System.IO.Path.GetTempPath & "\TraceLog.log")
 **Whatever you call your log file
then  add it to the mail message:
mymailmessage.attachments.add(attfile)

send the message
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39850973
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39852513
What must be confusing me is that when I run this page on Trace Write and Trace Warn, it has a bunch of information. I do understand how to retrieve an exception as a string. I thought I could retrieve the information displayed on this page and send it.

<%@ Page Language="VB" Trace="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  
    Try
      If (IsPostBack) Then
        
        Select Case Request.Form("__EVENTTARGET")
          Case "WarnLink"
            Throw New ArgumentException("Trace warn.")
          Case "WriteLink"
            Throw New InvalidOperationException("Trace write.")
          Case Else
            Throw New ArgumentException("General exception.")
        End Select  
      End If
    Catch ae As ArgumentException
      Trace.Warn("Exception Handling", "Warning: Page_Load.", ae)
    Catch ioe As InvalidOperationException
      Trace.Write("Exception Handling", "Exception: Page_Load.", ioe)
    End Try
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Trace Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        http://msdn.microsoft.com/en-us/library/z48bew18(v=vs.85).aspx
        <br /><br />
      <asp:LinkButton id="WriteLink" 
                      runat="server"
                      text="Generate Trace Write" />
      <asp:LinkButton id="WarnLink"
                      runat="server"
                      text="Generate Trace Warn" />
        <br /><br />
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 40
ID: 39852628
The Trace and Debug objects are designed for debugging purpose and do not always behave as other objects, specially when you use them with exceptions objects.

That is why I told you to call ToString on your exception object.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question