Click here to Skip to main content
15,881,833 members
Articles / Desktop Programming / WPF

Calcium: A Modular Application Toolset Leveraging PRISM – Part 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (48 votes)
23 Nov 2009BSD12 min read 116.1K   3   90  
Calcium provides much of what one needs to rapidly build a multifaceted and sophisticated modular application. Includes a host of modules and services, and an infrastructure that is ready to use in your next application.
/*
<File>
	<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
	<License see="prj:///Documentation/License.txt"/>
	<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
	<CreationDate>2007/11/19 20:00</CreationDate>
	<LastSubmissionDate>$Date: $</LastSubmissionDate>
	<Version>$Revision: $</Version>
	<Contributions>
		<Contribution><Date>2009-04-09</Date><Name>Michael Gerfen</Name>
						<Description>Added param support.</Description></Contribution>
	</Contributions>
</File>
*/

using System;
using System.Collections.Generic;

using DanielVaughan.Logging.ClientLogging;

namespace DanielVaughan.Logging
{
	/// <summary>
	/// A log is responsible for sending log messages to the server.
	/// </summary>
	public interface ILog
	{
		event EventHandler<InternalMessageEventArgs> InternalMessage;

		/// <summary>
		/// Gets the name of the log.
		/// This is used to filter log entries on the server.
		/// </summary>
		/// <value>The name of this log.</value>
		string Name
		{
			get;
		}

		/// <summary>
		/// Occurs when a log entry is sent to the server.
		/// </summary>
		event EventHandler<LogEventArgs> LogEntrySent;

		/// <summary>
		/// Occurs when any request to log is made.
		/// This will be raised at equal or greater frequency
		/// than the <see cref="LogEntrySent"/> <code>event</code>.
		/// </summary>
		event EventHandler<LogEventArgs> WriteRequested;

		#region Enabled properties
		/// <summary>
		/// Gets a value indicating whether debug is enabled. If <code>true</code>
		/// calls to Debug will be attempted, otherwise they will be ignored.
		/// </summary>
		/// <value><c>true</c> if debug is enabled; otherwise, <c>false</c>.</value>
		bool DebugEnabled
		{ 
			get;
		}

		/// <summary>
		/// Gets a value indicating whether info is enabled. If <code>true</code>
		/// calls to Info will be attempted, otherwise they will be ignored.
		/// </summary>
		/// <value><c>true</c> if info is enabled; otherwise, <c>false</c>.</value>
		bool InfoEnabled
		{ 
			get;
		}

		/// <summary>
		/// Gets a value indicating whether warn is enabled. If <code>true</code>
		/// calls to Warn will be attempted, otherwise they will be ignored.
		/// </summary>
		/// <value><c>true</c> if warn is enabled; otherwise, <c>false</c>.</value>
		bool WarnEnabled
		{ 
			get;
		}

		/// <summary>
		/// Gets a value indicating whether error is enabled. If <code>true</code>
		/// calls to Error will be attempted, otherwise they will be ignored.
		/// </summary>
		/// <value><c>true</c> if error is enabled; otherwise, <c>false</c>.</value>
		bool ErrorEnabled
		{ 
			get;
		}

		/// <summary>
		/// Gets a value indicating whether fatal is enabled. If <code>true</code>
		/// calls to Fatal will be attempted, otherwise they will be ignored.
		/// </summary>
		/// <value><c>true</c> if fatal is enabled; otherwise, <c>false</c>.</value>
		bool FatalEnabled
		{ 
			get;
		}
		#endregion

		#region Write methods
		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		void Debug(string message);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		void Debug(string message, Exception exception);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Debug(string message, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Debug(string message, Exception exception, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(Exception exception, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(Exception exception, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(Exception exception, IDictionary<string, object> properties, string message, params object[] args);


		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Debug"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void DebugFormat(Exception exception, IDictionary<string, object> properties, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		void Info(string message);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		void Info(string message, Exception exception);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Info(string message, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Info(string message, Exception exception, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(Exception exception, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(Exception exception, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(Exception exception, IDictionary<string, object> properties, string message, params object[] args);


		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Info"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void InfoFormat(Exception exception, IDictionary<string, object> properties, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		void Warn(string message);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		void Warn(string message, Exception exception);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Warn(string message, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Warn(string message, Exception exception, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(Exception exception, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(Exception exception, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(Exception exception, IDictionary<string, object> properties, string message, params object[] args);


		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Warn"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void WarnFormat(Exception exception, IDictionary<string, object> properties, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		void Error(string message);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		void Error(string message, Exception exception);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Error(string message, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Error(string message, Exception exception, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(Exception exception, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(Exception exception, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(Exception exception, IDictionary<string, object> properties, string message, params object[] args);


		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Error"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void ErrorFormat(Exception exception, IDictionary<string, object> properties, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		void Fatal(string message);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		void Fatal(string message, Exception exception);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Fatal(string message, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="exception">The exception that this message 
		/// is regarding.</param>
		/// <param name="properties">Custom properties 
		/// to add additional logging information.</param>
		void Fatal(string message, Exception exception, IDictionary<string, object> properties);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(Exception exception, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(Exception exception, IFormatProvider provider, string message, params object[] args);

		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(Exception exception, IDictionary<string, object> properties, string message, params object[] args);


		/// <summary>
		/// Writes a log entry at the <see cref="ClientLogging.LogLevel.Fatal"/>.
		/// </summary>
		/// <param name="exception">The exception that this message
		/// is regarding.</param>
		/// <param name="properties">Custom properties
		/// to add additional logging information.</param>
		/// <param name="provider">The provider which provides culture-specific formatting information.</param>
		/// <param name="message">The message to write.</param>
		/// <param name="args">The arguments used to format the supplied message.</param>
		void FatalFormat(Exception exception, IDictionary<string, object> properties, IFormatProvider provider, string message, params object[] args);
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Engineer
Switzerland Switzerland
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.

Previously Daniel was a nine-time Microsoft MVP and co-founder of Outcoder, a Swiss software and consulting company.

Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.

Daniel is the developer behind several acclaimed mobile apps including Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably Codon.

Would you like Daniel to bring value to your organisation? Please contact

Blog | Twitter


Xamarin Experts
Windows 10 Experts

Comments and Discussions