Solved

Custom Exception Publisher class to publish to database using Data Access application block

Posted on 2004-04-14
6
314 Views
Last Modified: 2012-06-21
I'm looking for examples of custom publishers and some walk throughs on the best way to create a custom publisher to keep track of multiple websites exceptions.
Some create table scripts would be nice as well..

Thanks for any input
0
Comment
Question by:jayrod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 10825081
you cancreatan error log and write to it

' Writes an entry to an existing log
Public Sub WriteLogEntry( _
     ByVal logName As String, _
     ByVal logSource As String, _
     ByVal logEntry As String, _
     ByVal logType As System.Diagnostics.EventLogEntryType, _
     ByVal logID As Integer, _
     ByVal category As Short)
    'Arguments : logName - The name of the log
    '            logSource - The source that writes the log
    '            logEntry - The text of the new message to log
    '            logType - The type of log to enter (error, failure
    '                       audit, information, success audit, warning)
    '            logID - An integer that sets the entry's ID
    '            category - The category for the entry

    Dim myLog As New System.Diagnostics.EventLog()
    myLog.Log = logName

    ' Create the source, if it does not already exist.
    If Not System.Diagnostics.EventLog.SourceExists(logSource) Then
        System.Diagnostics.EventLog.CreateEventSource(logSource, logName)
    End If

    myLog.WriteEntry(logSource, logEntry, logType, logID, category)

End Sub
0
 
LVL 3

Author Comment

by:jayrod
ID: 10825131
I use the error log now.. I'm looking for a database solution.

Thanks though
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 250 total points
ID: 10825923
in this case write logEntry to the Database

let me know if you need to know how
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Author Comment

by:jayrod
ID: 10826007
what i'm looking for is maybe an example table schema that someone would use to hold the exceptions (i know it's a sql thing but I thought the folks over in sql server wouldn't know what I meant)

and also how you use your new object?
0
 
LVL 20

Assisted Solution

by:ihenry
ihenry earned 250 total points
ID: 10937168
What if you have a .NET tool you can use in your custom publisher to output log messages to a variety of targets like windows log, database, xml or flat file, windows messenger, smtp and many more. Features with hierarchy logger instances, level of messages priority and FREE!

try this:
Log4Net, http://log4net.sourceforge.net/old-index.html

Now back to the question :)
When I need to log an error message, usually I need a few information like
1. Date and time when the error occurs
2. Machine and Domain name, it's useful for web app host in multiple web server
3. Current app user ( Thread.CurrentPrincipal.Identity.Name, useful for form based authentication or anything except windows authentication )
4. Current logged windows user ( WindowsIdentity.Name )
5. Error message description, off course
6. Error number, it happens sometimes you don't want the real message revealed for security reason and your custom exception will throw the error number description instead.
7. Anything else?
0
 
LVL 3

Author Comment

by:jayrod
ID: 10939190
This is the code I ended up using:

            void IExceptionPublisher.Publish(Exception exception, NameValueCollection AdditionalInfo, NameValueCollection ConfigSettings)
            {
                  SqlConnection connection = null;

                  // Create StringBuilder to maintain publishing information.
                  StringBuilder strInfo = new StringBuilder();
                  
                  // Record the contents of the AdditionalInfo collection.
                  if (AdditionalInfo != null)
                  {
                        // Record General information.
                        strInfo.AppendFormat("{0}General Information{0}", Environment.NewLine);
                        strInfo.AppendFormat("{0}Additonal Info:", Environment.NewLine);
                        foreach (string i in AdditionalInfo)
                        {
                              strInfo.AppendFormat("{0}{1}: {2}", Environment.NewLine, i, AdditionalInfo.Get(i));
                        }
                  }
                  // Append the exception text
                  strInfo.AppendFormat("{0}{0}Exception Information{0}{1}", Environment.NewLine, exception.ToString());
                  try
                  {
                        connection = Helper.GetConnection();                              

                        SqlParameter[] parms = new SqlParameter[4];
                        parms[0] = new SqlParameter("@excMessage", exception.Message);
                        parms[1] = new SqlParameter("@ExcSource", exception.Source);
                        parms[2] = new SqlParameter("@ExcTargetSite", exception.TargetSite.Name);
                        parms[3] = new SqlParameter("@ExcAddInfo", strInfo.ToString());

                        SqlHelper.ExecuteNonQuery(connection, CommandType.StoredProcedure, "[NRLFCU_MASTER].[dbo].ExceptionInsert_sp", parms);
                  }
                  catch(Exception ex)
                  {
                        throw(ex);
                  }
                  finally
                  {
                        if(connection != null)
                              connection.Dispose();
                  }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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