Solved

mailing myself the trace information

Posted on 2014-02-10
9
216 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:BobCSD
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 100 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 12

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
 
LVL 1

Author Comment

by:BobCSD
ID: 39850792
I must be missing something. I don't see an answer I can use in any of the responses.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 12

Accepted Solution

by:
ktaczala earned 400 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 12

Expert Comment

by:ktaczala
ID: 39850973
0
 
LVL 1

Author Comment

by:BobCSD
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now