MojoPortal is an ASP.NET content management system that is easily extensible by developers. Steve Land from VerifiedAD.com recently led a MojoPortal User's group on Yamisee.com on the topic of log4net, which is the logging infrastructure used by MojoPortal.
7. Everyone likes to write a logging framework “Writing your own logging framework is the perfect coding crime. If you can convince your manager to put it on the project plan, you are guaranteed to have success. At the end of each day, you will go home feeling happy and satisfied. It will feel like you are doing something creative. You will get the intellectual stimulation without the risk of failure.” Dr. Heinz M. Kabutz, The Java Specialists Newsletter Stan Wagon, Prof. of Mathematics and Computer Science, Macalester College, St. Paul, Minnesotahttp://decision-making.moshe-online.com/wheel.html
8. Basic concepts Tracing Dump every action and step, timestamped Logging Log business process steps Error Reporting / Debugging Log exceptions, unexpected cases
9. Log4Net features Log to multiple targets per log via Appenders Configurable message format Different logging levels off, fatal, error, warn, info, debug, and all Each logger has its own logging level Runtime control on which statements are printed Filters allow you to add conditions to Appenders to restrict what data gets written
11. Good things to log Startup / shutdown of application Object creation Scarce resource allocation Failures (recoverable / unrecoverable) How long performance-critical operations took
12. Levels and tips ALL DEBUG INFO WARN ERROR FATAL OFF Tips generally follow http://commons.apache.org/logging/guide.html Selected level and above are reported
13. DEBUG level Detailed information on the flow through the system. Expected exceptions that users of your code should handle. Logging details that you would not expect to see in production.
14. INFO level You generally want exception information available in production without having to turn on DEBUG log level. Log as INFO with stack trace and generally re-throw the exception. Components that rely on network boundaries should use INFO, don’t assume exceptions will make it to other components. Logging details that may be useful in production during troubleshooting.
15. WARN level Use of deprecated APIs, poor usage of APIs, “almost” errors, other unexpected and undesirable runtime situations that are not necessarily “wrong”
16. ERROR level Other runtime errors or unexpected conditions that may not cause premature termination.
18. Things to be careful about Ensure logs don’t contain sensitive data Consider how attackers could use logs to defeat your software. Don’t reveal more information than necessary. Recursive code with logging Definitions of levels Not too much logging When performance is important, don’t create logging related objects if logging is turned off
19.
20. Appenders In the box AdoNetAppender AspNetTraceAppender ConsoleAppender DebugAppender EventLogAppender FileAppender MemoryAppender RemotingAppender RollingFileAppender ( MojoPortal default) SmtpAppender SmtpPickupDirAppender … and more Or, make your own Start from scratch (probably don’t need to do this) Start from existing Appenderoverride methods that don’t do exactly what you want
21. Locking Models (for file appenders) MinimalLock: Opens the file once for each cycle. Slower but allows other processes to move/delete the log while logging ExclusiveLock: Opens the file once for writing and holds it open until CloseFile is called. Higher performance, but not appropriate for Web applications.
22. Layouts The recognized conversion pattern names are: log4net.Layout.PatternLayoutsee http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
Sailors on early ships had no real way of knowing how fast they were traveling and how far they had gone in a specific period of time. So a system of measuring was devised, using a log of wood.The log had a weight tied to one end and a long rope attaching the other end to the stern, or back of the ship. The log floated behind the ship a certain distance, the length the rope was let out.Written accounts of speed Log Book
AspNetTraceAppender outputs to trace screen of browser when @Page Trace=“true” setDebugAppender outputs events to the System.Diagnostics.Debug.Write(..) methodFileAppender has either Append or Overwrite modeMemoryAppender stores all to array, accessible via GetEvents() method RemotingAppender sends asynchronously