![]() ![]() The key is the exceptionManagement section. In order to use the custom publisher, you do not change anything in the application instead, you simply modify the app.config file. ![]() Assuming you compiled the code above into an assembly called myPublisher.dll, you’d reference that assembly in your client application. You’ll also need to reference the assembly holding the custom publisher. Then, you’ll be able to use the Publish method in order to log exceptions. You’ll want to add a reference to the namespace. The client application uses EMAB just as it did previously. Now, you must hook this custom publisher up to your client application. You have now created a custom publisher that publishes exception information to a centralized SQL Server. These lengths might not be adequate for all applications.Īfter creating the table, your complete code to insert records can be seen in Listing A. Note that there are three fields of 255 characters and one text field of “unlimited” length. The code for the SQL table looks like this: In this simple example, you have a SQL Server table created with the fields to hold the necessary information. You can format this data in any way necessary. NET Exception, you can use the properties to pull various pieces of information out of it. This code loops through the collection and uses a StringBuilder in order to build a string with all the additional information:Īt this point, you have an Exception that was passed in, and all the AdditionalInfo has been saved into a string. The easiest way is to move through the collection and build a string with the information. You’ll want to process the AdditionalInfo that is passed to you. The ConnectionString is very simple you’ll want to modify it based on your environment. In this simple example, you’ll also see an Imports statement for because the code will publish exception information to SQL Server. Finally, the last argument is ConfigSettings and allows you to modify the custom publisher from a configuration file. The second argument is AdditionalInfo and comes in the form of a NamedValueCollection this is why you imported the SystemCollections.Specialized namespace. The first parameter is of type System.Exception, which is the same exception you capture normally using the Try…Catch syntax. The Publish method accepts three parameters. Publish is the only method you need to worry about, thanks to the simplicity of the EMAB. You could also implement IExceptionXmlPublisher if you prefer to receive exception details in XML format.Īs soon as you implement the interface, Visual Studio gives you the skeleton for the Publish method you must implement. After declaring the class, you implement the interface with this line: Other Imports will be used in this project, as you can see in the full code listing ( Listing A). In order to work with the data that is returned from the ExceptionManager, you’ll also want to add the following line just after the previous one: This DLL contains the two interfaces mentioned above, one of which must be inherited by your component.Īfter adding the reference to the DLL, add the following line to the top of the file: To create a custom publisher, you start a new Class Library project in Visual Studio. You get the interfaces as part of the EMAB projects you download (see previous article for more on downloading and building the EMAB projects). In order to create the custom publisher, you inherit either the IExceptionPublisher or IExceptionXmlPublisher. Instead, it might make more sense to log to a centralized server such as a SQL Server database. The EMAB document discusses logging to text files, but that doesn’t seem too exciting. If you’ve got a distributed application running on a number of desktop machines, this means exceptions are recorded in the local application logs on those machines, which leaves the developers completely unaware there are any problems with the application.įortunately, EMAB is extensible, allowing you to create custom publishers. One of the potential drawbacks to EMAB is that by default, it logs to the Application Log on the computer where the application is running. The ability to change some logging features without recompiling the application.The ability to log to any source, although this requires some extra effort.The ability to turn EMAB on and off without recompiling the application.Single-line exception logging in your application.To review, important EMAB features include: In a previous article, I discussed how Microsoft’s Exception Management Application Block (EMAB) made it easy to log exceptions using a single line of code. ![]() Use the Exception Management Application Block and your SQL Server to create a centralized store for all exceptions in your application. Custom publishers for the Exception Management Application BlockĪ distributed application that stores its exception log on each individual machine is pretty worthless. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |