logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject cvs commit: logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender FireEventAppender.cs MessageBoxAppender.cs SimpleSmtpAppender.cs
Date Wed, 13 Oct 2004 21:38:23 GMT
nicko       2004/10/13 14:38:23

  Added:       examples/net/1.0/Appenders nant.build nant.config
               examples/net/1.0/Appenders/SampleAppendersApp nant.build
                        nant.config
               examples/net/1.0/Appenders/SampleAppendersApp/cs .cvsignore
                        nant.build nant.config
               examples/net/1.0/Appenders/SampleAppendersApp/cs/src
                        .cvsignore App.config AssemblyInfo.cs
                        LoggingExample.cs SampleAppendersApp.csproj
               examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender
                        FireEventAppender.cs MessageBoxAppender.cs
                        SimpleSmtpAppender.cs
  Log:
  Added example appenders project
  
  Revision  Changes    Path
  1.1                  logging-log4net/examples/net/1.0/Appenders/nant.build
  
  Index: nant.build
  ===================================================================
  <?xml version="1.0" ?>
  <project name="appender-examples" default="compile" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- compile Tutorials examples -->
      <target name="compile" description="Builds Appender examples">
          <nant target="compile">
              <buildfiles>
                  <include name="*/nant.build" />
                  <!-- exclude current build file -->
                  <exclude name="exclude.build" />
              </buildfiles>
          </nant>
      </target>
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/nant.config
  
  Index: nant.config
  ===================================================================
  <?xml version="1.0" ?>
  <project name="configuration" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- Include parent configuration file -->
      <include buildfile="../nant.config" />
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/nant.build
  
  Index: nant.build
  ===================================================================
  <?xml version="1.0" ?>
  <project name="sampleappendersapp-example" default="compile" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- compile ConsoleApp example -->
      <target name="compile" description="Builds SampleAppendersApp example">
          <nant target="compile">
              <buildfiles>
                  <include name="*/nant.build" />
                  <!-- exclude current build file -->
                  <exclude name="exclude.build" />
              </buildfiles>
          </nant>
      </target>
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/nant.config
  
  Index: nant.config
  ===================================================================
  <?xml version="1.0" ?>
  <project name="configuration" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- Include parent configuration file -->
      <include buildfile="../nant.config" />
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  bin
  doc
  build
  
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build
  
  Index: nant.build
  ===================================================================
  <?xml version="1.0" ?>
  <project name="sampleappendersapp-cs-exa,ple" default="compile" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- Include configuration file -->
      <include buildfile="nant.config" />
      <!-- Include log4net helpers -->
      <include buildfile="${log4net.basedir}/log4net.include" />
      <!-- Targets that should always be executed -->
      <call target="set-build-configuration" />
      <call target="set-${project.runtime.config}-${project.runtime.version}-runtime-configuration"
/>
      <!-- Target for compiling the example -->
      <target name="compile" description="Builds the example" depends="check-current-bin-dir,
clean-current-bin-dir, check-current-build-defines, check-current-build-config, check-current-build-debug,
check-log4net-assembly">
          <!-- copy log4net build output  -->
          <copy todir="${current.bin.dir}">
              <fileset basedir="${log4net.output.dir}">
                  <include name="*.*" />
              </fileset>
          </copy>
          <!-- compile the example -->
          <csc noconfig="true" target="exe" warnaserror="true" debug="${current.build.debug}"
define="${current.build.defines.csc}" output="${current.bin.dir}/ConsoleApp.exe">
              <sources>
                  <include name="src/**/*.cs" />
                  <include name="${log4net.basedir}/src/AssemblyVersionInfo.cs" />
              </sources>
              <references basedir="${current.bin.dir}">
                  <include name="log4net.dll" />
                  <include name="System.dll" />
                  <include name="System.Web.dll" />
                  <include name="System.Windows.Forms.dll" />
              </references>
          </csc>
          <!-- copy the ConsoleApp application configuration file -->
          <copy file="src/App.config" tofile="${current.bin.dir}/ConsoleApp.exe.config"
/>
      </target>
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.config
  
  Index: nant.config
  ===================================================================
  <?xml version="1.0" ?>
  <project name="configuration" xmlnds="http://tempuri.org/nant-vs.xsd">
      <!-- Include parent configuration file -->
      <include buildfile="../nant.config" />
      <!-- Set log4net base directory -->
      <property name="log4net.basedir" value="../../../../../../" />
  </project>
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  obj
  *.csproj.user
  bin
  doc
  
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config
  
  Index: App.config
  ===================================================================
  <?xml version="1.0" encoding="utf-8" ?>
  <!-- 
  		.NET application configuration file     
  		This file must have the exact same name as your application with .config appended to it.

  		
  		For example if your application is ConsoleApp.exe then the config file must be ConsoleApp.exe.config.

  		It must also be in the same directory as the application. 
  	-->
  <configuration>
  	<!-- Register a section handler for the log4net section -->
  	<configSections>
  		<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
  	</configSections>
  	
  	<appSettings>
  		<!-- To enable internal log4net logging specify the following appSettings key -->
  		<!-- <add key="log4net.Internal.Debug" value="true"/> -->
  	</appSettings>
  	
  	<!-- This section contains the log4net configuration settings -->
  	<log4net>
  
  		<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  			<layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger
- %message%newline" />
  		</appender>
  		
  		<appender name="MessageBoxAppender" type="SampleAppendersApp.Appender.MessageBoxAppender,
SampleAppendersApp">
  
  			<layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger
[%ndc] &lt;%property{auth}&gt; - %message%newline"/>
  			<titleLayout type="log4net.Layout.PatternLayout" value="LoggingEvent: %-5level %logger"/>
  			<mapping>
  				<level value="ERROR" />
  				<icon value="Error" />
  			</mapping>
  			
  		</appender>
  		
  		
  		<appender name="FireEventAppender" type="SampleAppendersApp.Appender.FireEventAppender,
SampleAppendersApp">
  		</appender>
  		
  		<appender name="SimpleSmtpAppender" type="SampleAppendersApp.Appender.SimpleSmtpAppender,
SampleAppendersApp">
  			<layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger
- %message%newline" />
  			<subject value="%-5level %logger" />
  			
  			<to value="you@me.co.uk" />
  			<from value="me@me.co.uk" />
  			<smtpHost value="my-smtp-server" /> 
  		</appender>
  
  		<!-- Setup the root category, add the appenders and set the default level -->
  		<root>
  			<level value="ALL" />
  			<appender-ref ref="ConsoleAppender" />
  			<appender-ref ref="MessageBoxAppender" />
  			<appender-ref ref="FireEventAppender" />
  			<appender-ref ref="SimpleSmtpAppender" />
  		</root>
  		
  	</log4net>
  </configuration>
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/AssemblyInfo.cs
  
  Index: AssemblyInfo.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System.Reflection;
  using System.Runtime.CompilerServices;
  
  //
  // General Information about an assembly is controlled through the following 
  // set of attributes. Change these attribute values to modify the information
  // associated with an assembly.
  //
  [assembly: AssemblyTitle("log4net - SampleAppendersApp")]
  [assembly: AssemblyDescription("log4net SampleAppendersApp")]
  [assembly: AssemblyConfiguration("")]
  [assembly: AssemblyCompany("The Apache Software Foundation")]
  [assembly: AssemblyProduct("log4net - SampleAppendersApp")]
  [assembly: AssemblyCopyright("Copyright 2001-2004 The Apache Software Foundation.")]
  [assembly: AssemblyTrademark("Copyright 2001-2004 The Apache Software Foundation.")]
  [assembly: AssemblyCulture("")]		
  
  //
  // In order to sign your assembly you must specify a key to use. Refer to the 
  // Microsoft .NET Framework documentation for more information on assembly signing.
  //
  // Use the attributes below to control which key is used for signing. 
  //
  // Notes: 
  //   (*) If no key is specified, the assembly is not signed.
  //   (*) KeyName refers to a key that has been installed in the Crypto Service
  //       Provider (CSP) on your machine. KeyFile refers to a file which contains
  //       a key.
  //   (*) If the KeyFile and the KeyName values are both specified, the 
  //       following processing occurs:
  //       (1) If the KeyName can be found in the CSP, that key is used.
  //       (2) If the KeyName does not exist and the KeyFile does exist, the key 
  //           in the KeyFile is installed into the CSP and used.
  //   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
  //       When specifying the KeyFile, the location of the KeyFile should be
  //       relative to the project output directory which is
  //       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
  //       located in the project directory, you would specify the AssemblyKeyFile 
  //       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
  //   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
  //       documentation for more information on this.
  //
  [assembly: AssemblyDelaySign(false)]
  [assembly: AssemblyKeyFile("")]
  [assembly: AssemblyKeyName("")]
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/LoggingExample.cs
  
  Index: LoggingExample.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System;
  
  using SampleAppendersApp.Appender;
  
  // Configure log4net using the .config file
  [assembly: log4net.Config.XmlConfigurator(Watch=true)]
  // This will cause log4net to look for a configuration file
  // called ConsoleApp.exe.config in the application base
  // directory (i.e. the directory containing SampleAppendersApp.exe)
  
  namespace SampleAppendersApp
  {
  	/// <summary>
  	/// Example of how to simply configure and use log4net
  	/// </summary>
  	public class LoggingExample
  	{
  		// Create a logger for use in this class
  		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  		// NOTE that using System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
  		// is equivalent to typeof(LoggingExample) but is more portable
  		// i.e. you can copy the code directly into another class without
  		// needing to edit the code.
  
  		/// <summary>
  		/// Application entry point
  		/// </summary>
  		/// <param name="args">command line arguments</param>
  		public static void Main(string[] args)
  		{
  			// Hookup the FireEventAppender event
  			if (FireEventAppender.Instance != null)
  			{
  				FireEventAppender.Instance.MessageLoggedEvent += new MessageLoggedEventHandler(FireEventAppender_MessageLoggedEventHandler);
  			}
  
  			// Log an info level message
  			if (log.IsInfoEnabled) log.Info("Application [ConsoleApp] Start");
  
  			// Log a debug message. Test if debug is enabled before
  			// attempting to log the message. This is not required but
  			// can make running without logging faster.
  			if (log.IsDebugEnabled) log.Debug("This is a debug message");
  
  			try
  			{
  				Bar();
  			}
  			catch(Exception ex)
  			{
  				// Log an error with an exception
  				log.Error("Exception thrown from method Bar", ex);
  			}
  
  			log.Error("Hey this is an error!");
  
  			// Log an info level message
  			if (log.IsInfoEnabled) log.Info("Application [ConsoleApp] End");
  
  			Console.Write("Press Enter to exit...");
  			Console.ReadLine();
  		}
  
  		// Helper methods to demonstrate location information and nested exceptions
  
  		private static void Bar()
  		{
  			Goo();
  		}
  
  		private static void Foo()
  		{
  			throw new Exception("This is an Exception");
  		}
  
  		private static void Goo()
  		{
  			try
  			{
  				Foo();
  			}
  			catch(Exception ex)
  			{
  				throw new ArithmeticException("Failed in Goo. Calling Foo. Inner Exception provided",
ex);
  			}
  		}
  
  		private static void FireEventAppender_MessageLoggedEventHandler(object sender, MessageLoggedEventArgs
e)
  		{
  			System.Diagnostics.Trace.WriteLine("EVENT ****" + e.LoggingEvent.RenderedMessage + "****");
  		}
  	}
  }
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj
  
  Index: SampleAppendersApp.csproj
  ===================================================================
  <VisualStudioProject>
      <CSHARP
          ProjectType = "Local"
          ProductVersion = "7.0.9466"
          SchemaVersion = "1.0"
          ProjectGuid = "{9E715F72-7F70-421B-A2BF-E9CB42F88F5C}"
      >
          <Build>
              <Settings
                  ApplicationIcon = ""
                  AssemblyKeyContainerName = ""
                  AssemblyName = "SampleAppendersApp"
                  AssemblyOriginatorKeyFile = ""
                  DefaultClientScript = "JScript"
                  DefaultHTMLPageLayout = "Grid"
                  DefaultTargetSchema = "IE50"
                  DelaySign = "false"
                  OutputType = "Exe"
                  PreBuildEvent = ""
                  PostBuildEvent = ""
                  RootNamespace = "SampleAppendersApp"
                  RunPostBuildEvent = "OnBuildSuccess"
                  StartupObject = "SampleAppendersApp.LoggingExample"
              >
                  <Config
                      Name = "Debug"
                      AllowUnsafeBlocks = "false"
                      BaseAddress = "285212672"
                      CheckForOverflowUnderflow = "false"
                      ConfigurationOverrideFile = ""
                      DefineConstants = "DEBUG;TRACE"
                      DocumentationFile = ""
                      DebugSymbols = "true"
                      FileAlignment = "4096"
                      IncrementalBuild = "true"
                      NoStdLib = "false"
                      NoWarn = ""
                      Optimize = "false"
                      OutputPath = "..\build\debug\"
                      RegisterForComInterop = "false"
                      RemoveIntegerChecks = "false"
                      TreatWarningsAsErrors = "false"
                      WarningLevel = "4"
                  />
                  <Config
                      Name = "Release"
                      AllowUnsafeBlocks = "false"
                      BaseAddress = "285212672"
                      CheckForOverflowUnderflow = "false"
                      ConfigurationOverrideFile = ""
                      DefineConstants = "TRACE"
                      DocumentationFile = ""
                      DebugSymbols = "false"
                      FileAlignment = "4096"
                      IncrementalBuild = "true"
                      NoStdLib = "false"
                      NoWarn = ""
                      Optimize = "true"
                      OutputPath = "..\build\release\"
                      RegisterForComInterop = "false"
                      RemoveIntegerChecks = "false"
                      TreatWarningsAsErrors = "false"
                      WarningLevel = "4"
                  />
              </Settings>
              <References>
                  <Reference
                      Name = "System"
                      AssemblyName = "System"
                  />
                  <Reference
                      Name = "System.Data"
                      AssemblyName = "System.Data"
                  />
                  <Reference
                      Name = "System.XML"
                      AssemblyName = "System.Xml"
                  />
                  <Reference
                      Name = "log4net"
                      AssemblyName = "log4net"
                      HintPath = "..\..\..\..\..\..\..\bin\net\1.0\release\log4net.dll"
                  />
                  <Reference
                      Name = "System.Windows.Forms"
                      AssemblyName = "System.Windows.Forms"
                      HintPath = "..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
                  />
                  <Reference
                      Name = "System.Web"
                      AssemblyName = "System.Web"
                      HintPath = "..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
                  />
              </References>
          </Build>
          <Files>
              <Include>
                  <File
                      RelPath = "App.config"
                      BuildAction = "None"
                  />
                  <File
                      RelPath = "AssemblyInfo.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "AssemblyVersionInfo.cs"
                      Link = "..\..\..\..\..\..\..\src\AssemblyVersionInfo.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "LoggingExample.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Appender\FireEventAppender.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Appender\MessageBoxAppender.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
                  <File
                      RelPath = "Appender\SimpleSmtpAppender.cs"
                      SubType = "Code"
                      BuildAction = "Compile"
                  />
              </Include>
          </Files>
      </CSHARP>
  </VisualStudioProject>
  
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender/FireEventAppender.cs
  
  Index: FireEventAppender.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System;
  
  using log4net.Core;
  
  namespace SampleAppendersApp.Appender
  {
  	public delegate void MessageLoggedEventHandler(object sender, MessageLoggedEventArgs e);
  
  	public class MessageLoggedEventArgs : EventArgs
  	{
  		private LoggingEvent m_loggingEvent;
  
  		public MessageLoggedEventArgs(LoggingEvent loggingEvent)
  		{
  			m_loggingEvent = loggingEvent;
  		}
  		public LoggingEvent LoggingEvent
  		{
  			get { return m_loggingEvent; }
  		}
  	}
  
  	public class FireEventAppender : log4net.Appender.AppenderSkeleton
  	{
  		private static FireEventAppender m_instance;
  
  		private FixFlags m_fixFlags = FixFlags.All;
  
  		// Event handler
  		public event MessageLoggedEventHandler MessageLoggedEvent;
  
  		// Easy singleton, gets the last instance created
  		public static FireEventAppender Instance
  		{
  			get { return m_instance; }
  		}
  
  		public FireEventAppender()
  		{
  			// Store the instance created
  			m_instance = this;
  		}
  
  		virtual public FixFlags Fix
  		{
  			get { return m_fixFlags; }
  			set { m_fixFlags = value; }
  		}
  
  		override protected void Append(LoggingEvent loggingEvent) 
  		{
  			// Because we the LoggingEvent may be used beyond the lifetime 
  			// of the Append() method we must fix any volatile data in the event
  			loggingEvent.Fix = this.Fix;
  
  			// Raise the event
  			MessageLoggedEventHandler handler = MessageLoggedEvent;
  			if (handler != null)
  			{
  				handler(this, new MessageLoggedEventArgs(loggingEvent));
  			}
  		} 
  	}
  }
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender/MessageBoxAppender.cs
  
  Index: MessageBoxAppender.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System;
  using System.IO;
  using System.Windows.Forms;
  
  using log4net.Appender;
  using log4net.Core;
  using log4net.Layout;
  using log4net.Util;
  
  namespace SampleAppendersApp.Appender
  {
  	public class MessageBoxAppender : AppenderSkeleton
  	{
  		private PatternLayout m_titleLayout;
  		private LevelMapping m_levelMapping = new LevelMapping();
  
  		public MessageBoxAppender()
  		{
  		}
  
  		public void AddMapping(LevelIcon mapping)
  		{
  			m_levelMapping.Add(mapping);
  		}
  
  		public PatternLayout TitleLayout
  		{
  			get { return m_titleLayout; }
  			set { m_titleLayout = value; }
  		}
  
  		override protected void Append(LoggingEvent loggingEvent) 
  		{
  			MessageBoxIcon messageBoxIcon = MessageBoxIcon.Information;
  
  			LevelIcon levelIcon = m_levelMapping.Lookup(loggingEvent.Level) as LevelIcon;
  			if (levelIcon != null)
  			{
  				// Prepend the Ansi Color code
  				messageBoxIcon = levelIcon.Icon;
  			}
  
  			string message = RenderLoggingEvent(loggingEvent);
  
  			string title = null;
  			if (m_titleLayout == null)
  			{
  				title = "LoggingEvent: "+loggingEvent.Level.Name;
  			}
  			else
  			{
  				StringWriter titleWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
  				m_titleLayout.Format(titleWriter, loggingEvent);
  				title = titleWriter.ToString();
  			}
  
  			MessageBox.Show(message, title, MessageBoxButtons.OK, messageBoxIcon);
  		} 
  
  		public override void ActivateOptions()
  		{
  			base.ActivateOptions();
  			m_levelMapping.ActivateOptions();
  		}
  
  		public class LevelIcon : LevelMappingEntry
  		{
  			private MessageBoxIcon m_icon;
  
  			public MessageBoxIcon Icon
  			{
  				get { return m_icon; }
  				set { m_icon = value; }
  			}
  		}
  	}
  }
  
  
  
  1.1                  logging-log4net/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/Appender/SimpleSmtpAppender.cs
  
  Index: SimpleSmtpAppender.cs
  ===================================================================
  #region Copyright & License
  //
  // Copyright 2001-2004 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  //
  #endregion
  
  using System;
  using System.IO;
  using System.Web.Mail;
  
  using log4net.Layout;
  using log4net.Core;
  using log4net.Util;
  using log4net.Appender;
  
  namespace SampleAppendersApp.Appender
  {
  	public class SimpleSmtpAppender : AppenderSkeleton
  	{
  		public SimpleSmtpAppender()
  		{	
  		}
  
  		public string To 
  		{
  			get { return m_to; }
  			set { m_to = value; }
  		}
  
  		public string From 
  		{
  			get { return m_from; }
  			set { m_from = value; }
  		}
  
  		public PatternLayout Subject 
  		{
  			get { return m_subjectLayout; }
  			set { m_subjectLayout = value; }
  		}
    
  		public string SmtpHost
  		{
  			get { return m_smtpHost; }
  			set { m_smtpHost = value; }
  		}
  
  		#region Override implementation of AppenderSkeleton
  
  		override protected void Append(LoggingEvent loggingEvent) 
  		{
  			try 
  			{	  
  				StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
  
  				string t = Layout.Header;
  				if (t != null)
  				{
  					writer.Write(t);
  				}
  
  				// Render the event and append the text to the buffer
  				RenderLoggingEvent(writer, loggingEvent);
  
  				t = Layout.Footer;
  				if (t != null)
  				{
  					writer.Write(t);
  				}
  
  				MailMessage mailMessage = new MailMessage();
  				mailMessage.Body = writer.ToString();
  				mailMessage.From = m_from;
  				mailMessage.To = m_to;
  
  				if (m_subjectLayout == null)
  				{
  					mailMessage.Subject = "Missing Subject Layout";
  				}
  				else
  				{
  					StringWriter subjectWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
  					m_subjectLayout.Format(subjectWriter, loggingEvent);
  					mailMessage.Subject = subjectWriter.ToString();
  				}
  
  				if (m_smtpHost != null && m_smtpHost.Length > 0)
  				{
  					SmtpMail.SmtpServer = m_smtpHost;
  				}
  
  				SmtpMail.Send(mailMessage);
  			} 
  			catch(Exception e) 
  			{
  				ErrorHandler.Error("Error occurred while sending e-mail notification.", e);
  			}		
  		}
  
  		override protected bool RequiresLayout
  		{
  			get { return true; }
  		}
  
  		#endregion // Override implementation of AppenderSkeleton
  
  		private string m_to;
  		private string m_from;
  		private PatternLayout m_subjectLayout;
  		private string m_smtpHost;
  	}
  }
  
  

Mime
View raw message