Freigeben über


MSDN Magazine article on building your own application block

The July 2006 edition of MSDN Magazine arrived in my mailbox today, and it contains a great article called Speed Development With Custom Application Blocks For Enterprise Library written by Mark Seeman. In this day of digital everything, it's nice to actually be able to hold something tangible in your hand - so I read the article on my balcony while enjoying the afternoon sun. But for those of you without some combination of an MSDN Magazine subscription, a balcony, or the sun, the link above will take you to ths same content online.

Comments

  • Anonymous
    June 12, 2006
    Hi Tom,

    Quick question about instrumentation in Ent Lib 2.0. I am trying to follow the documentation and instrument my own classes using [InstrumentationListener] and [InstrumentationProvider] but have had no luck so far. Is there anything specific that needs to be done in order to actually make it work?
    Any comments would be very much appreciated!

    Here is the code from the Ent Lib documentation which I tried:

    public partial class Form1 : Form
    {
      public Form1()
      {
          InitializeComponent();
      }

      private void button1_Click
        (object sender, EventArgs e)
      {
        MyApplication appl =
        new MyApplication();
        //IT FAILS AT THIS POINT SAYING
        //Object reference not set
        //to an instance of an object.
        appl.FireOnDbConnect();
      }
    }

    [InstrumentationListener(typeof(MyListener))]
    public class MyApplication
    {
    [InstrumentationProvider("DbConnect")]
    public event EventHandler<EventArgs>
         OnDbConnect;

    public void FireOnDbConnect()
    {
      OnDbConnect(this, new EventArgs());
    }
    }


    public class MyListener
    {
    public MyListener(string instanceName,
         bool a, bool b, bool c)
     { }
    [InstrumentationConsumer("DbConnect")]
        public void ConnectObserved
          (object sender, EventArgs e)
        {
          Console.WriteLine(
              "I saw a Database Connect.");
        }
    }

  • Anonymous
    June 12, 2006
    ... just a quick comment about my last question about instrumentation. I did reference Common and ObjectBuilder DLLs and set enabled Instrumentation in the config file.
    Cheers,
    Dmitry
  • Anonymous
    June 12, 2006
    ...further to my previous post about Instrumentation. After digging Ent Lib 2.0 source code I finally was able to instrument my own classes. It would be very helpful if this topic could get a little bit more coverage in the documentation since the examples that are provided there aren't really enough. Other than that I must say it works great!

    Dmitry
  • Anonymous
    June 20, 2006
    Hi all,
    I had asked a related question, but let me re-word the problem.
    I'm trying to log extra information depending on the type of exception that occurs. When defining a policy with the Enterprise Handling Configuration Tool all the exceptions that are caught are logged the same, this is, the logged entry has the following properties:

    Timestamp: {timestamp}
    Message: {message}
    Category: {category}
    Priority: {priority}
    EventId: {eventid}
    Severity: {severity}
    Title:{title}
    Machine: {machine}
    Application Domain: {appDomain}
    Process Id: {processId}
    Process Name: {processName}
    Win32 Thread Id: {win32ThreadId}
    Thread Name: {threadName}
    Extended Properties: {dictionary({key} - {value} )}


    However an HttpUnhandledException is logged the same way as a System.Net.WebException, we would like to log the WebExceptionStatus.ProtocolError for this type of exception. This is we would like to log the extra properties depending on the type of the exception. The Extended Properties dictionary is empty in all cases.

    How do we log extra properties such as the query string, the page name, the authenticated user and so on? What do we tweak while we define the policy using the Exception Handling Tool to log this extra information?

    Thanks in advanced,

    Lizet
  • Anonymous
    June 23, 2006
    Hi All,

    I am using DatabaseTraceListener for some of my Categories. So i find script in enterprise library and run in my database.In the configuration i till this is my addstoredprocedure and writelogstoredprocedure.

    and it all runs fine.


    But i want add more attributes..like

    SiteName, UserName and some other info logged into the database.

    How can i do that?


    Somebody please refer me a document or i can look for such information.

    thanx



  • Anonymous
    June 23, 2006
    Krishna - you'll need to modify your database schema, and then modify the code for the DatabaseTraceListener to insert the desired data into your new columns.

    Tom
  • Anonymous
    July 06, 2006
    Just posted a sample code for the intrumentation on msdn forums. Here is the link: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=534272&SiteID=1&mode=1