Log Messages
- It's simple to create detailed and informative logs with a minimal amount of code:
protected void Log(string Category, string Message) { LogEntry logEntry = new LogEntry(); logEntry.Categories.Add(Category); logEntry.Title = Application.ProductName; logEntry.EventId = ++eventId; logEntry.Priority = 0; logEntry.Message = Message; logEntry.ExtendedProperties.Add("Protocol", ProtocolName()); Logger.Write(logEntry); }
- No coding is necessary to specify the destination of the log messages. A simple configuration change will route the log messages to a flat file, a database, an e-mail address, the system event log, and so on. You can even filter messages based on their category or priority with a configuration change.
- The sample app leverages the Enterprise Library's Exception Handling Application Block to manage exceptions. This application block lets you create named exception policies in a configuration file and use the policies in source code:
catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "policy")) { throw; } }
The effect of this code depends on the configuration file. The policy can specify that the exception is rethrown, replaced with a different exception, wrapped in another exception, or logged. If the exception should be thrown, HandleException will return True.
The S3 web service is a simple way to store and retrieve data over the Internet. But if you already have access to an FTP site and can live with the security drawbacks, you can use the .NET 2.0 FtpWebRequest class instead. In either case, the .NET 2.0 GZipStream class is a convenient way to compress data to conserve bandwidth and storage space. The Microsoft Enterprise Library contains some invaluable Application Blocks that simplify application development, and let many important modifications be accomplished with configuration updates rather than code changes. The cryptography, logging, and Exception Handling Application Blocks simplified the sample app's design and coding. I recommend you download the Enterprise Library and familiarize yourself with all of its capabilities. And if you ever troubleshoot Internet applications, you're "flying blind" without a network capture and analysis tool like Packetyzer.