Open Source .NET Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source .NET Development [Electronic resources] - نسخه متنی

Brian Nantz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Application Logging


There are many logging components available today, both Open Source and proprietary. Microsoft and others working on the CLI specification had the foresight to build logging into System.Diagnostics.Trace. By using the Trace class in conjunction with System.Diagnostics.TraceListner, System.Diagnostics.Switch, and their child classes, you can do rudimentary logging using only the CLI. Most developers find that the built-in CLI framework's functionality is better than that of previous languages but still lacking in that they cannot log to the targets they want or log in a specific, configurable way.

TIP

As shown later in Table 8.3, Log4NET has a TraceAppender output that can output just like a regular TraceListener but of course with a lot more configurable outputs.

Table 8.3. Log4Net Appenders

Type

Description

ADONetAppender

Writes logging events to a database using either prepared statements or stored procedures.

ASPNetTraceAppender

Writes logging events to the ASP trace context. These can then be rendered at the end of the ASP page or on the ASP trace page.

BufferingForwardingAppender

Buffers logging events before forwarding them to child Appenders.

ConsoleAppender

Writes logging events to the application's Console. The events may go to either the standard output stream or the standard error stream.

EventLogAppender

Writes logging events to the Windows Event Log.

FileAppender

Writes logging events to the Windows Event Log.

ForwardingAppender

Forwards logging events to child Appenders.

MemoryAppender

Stores logging events in a memory buffer.

NetSendAppender

Writes logging events to the Windows Messenger service. These messages are displayed in a dialog on a user's terminal.

OutputDebugStringAppender

Writes logging events to the debugger. If the application has no debugger, the system debugger displays the string. If the application has no debugger and the system debugger is not active, the message is ignored.

RemotingAppender

Writes logging events to a remoting sink using .NET Remoting.

RollingFileAppender

Writes logging events to a file in the file system. The RollingFileAppender can be configured to log to multiple files based upon date or file size constraints.

SMTPAppender

Sends logging events to an email address.

TraceAppender

Writes logging events to the .NET trace system.

UdpAppender

Sends logging events as connectionless UDP datagrams to a remote host or a multicast group using a UdpClient.

Several other logging frameworks have been created for .NET. Microsoft's Patterns & Practices group created an Exception Management Block (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/emab-rm.asp) that is a little better than the CLI logging at being exception-aware, and they recently announced the Logging Application Block (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/Logging.asp?frame=true) that goes even further into application logging under some sort of end user license agreement. Justin Rudd originally ported LogKit (http://avalon.apache.org/logkit/), another Apache project, and I added a lot of functionality to it. You can find it at http://www.sourceforge.net/projects/logkit-net.

NOTE


Watch for the C# version of the Apache group's Avalon framework (http://www.apache.org/~hammett/avalondotnet/indexl). This project will provide a standard way to handle exceptions, logging, advanced serialization, and more! Similar projects are available under shared source from Microsoft's Pattern & Practices group (see the Application Blocks available from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/emab-rm.asp).

By far, the best logging kit available on the market happens to be Log4Net (http://log4net.sourceforge.net), and it also happens to be Open Source. Log4Net is a .NET port of a popular Java tool, Log4J. Log4J is a stable tool that has seen a lot of runtime and has been ported to many languages with great success. It's based on the research of the SEMPER (http://www.semper.org) group who, commissioned by the European Union to create a secure framework for e-commerce, decided to create their own logging API.

Some developers, especially with a C++ background, do not initially see the advantages of runtime logging over compile-time tracing. While allowing the compiler to map out all trace statements is the most popular type of logging available, it is not at all flexible. Runtime logging offers the advantage of setting and changing level thresholds at runtime for the code or even turning the logging off altogether. The advantages of this type of flexibility outweigh the proportionately small performance loss in most developers' minds.


    / 275