[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-04-14
6
Medium Priority
?
318 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 750 total points
ID: 10825923
in this case write logEntry to the Database

let me know if you need to know how
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 750 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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)…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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.…

650 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