Author: nicko
Date: Sun Oct 30 16:18:23 2005
New Revision: 329671
URL: http://svn.apache.org/viewcvs?rev=329671&view=rev
Log:
LOG4NET-51 WmiAppender. Added sample WmiAppender.
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/ (with
props)
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.build
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.config
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/
(with props)
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/AssemblyInfo.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/IWmiBoundEvent.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.csproj
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiInstaller.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLayout.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLoggingEvent.cs
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.build
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.config
Modified:
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj
logging/log4net/trunk/examples/net/1.0/cs-examples.sln
Modified:
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build?rev=329671&r1=329670&r2=329671&view=diff
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build
(original)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/nant.build
Sun Oct 30 16:18:23 2005
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project name="sampleappendersapp-cs-exa,ple" default="compile"
xmlnds="http://tempuri.org/nant-vs.xsd">
+<project name="sampleappendersapp-cs-example" default="compile"
xmlnds="http://tempuri.org/nant-vs.xsd">
<!-- Include configuration file -->
<include buildfile="nant.config" />
<!-- Include log4net helpers -->
Modified:
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config?rev=329671&r1=329670&r2=329671&view=diff
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config
(original)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/App.config
Sun Oct 30 16:18:23 2005
@@ -20,6 +20,9 @@
<!-- This section contains the log4net configuration settings -->
<log4net>
+ <appender name="WmiAppender"
type="log4net.Appender.WmiAppender,log4net.Appender.WmiAppender">
+ </appender>
+
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout"
value="%date [%thread] %-5level %logger - %message%newline" />
</appender>
@@ -85,6 +88,7 @@
<root>
<level value="ALL" />
+ <appender-ref ref="WmiAppender" />
<appender-ref ref="PatternFileAppender" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="MessageObjectExpanderAppender" />
@@ -92,11 +96,9 @@
<appender-ref ref="FireEventAppender" />
<appender-ref ref="SimpleSmtpAppender" />
<appender-ref ref="MsmqAppender" />
-
- <!--
<appender-ref ref="AsyncConsoleAppender" />
<appender-ref ref="FastDbAppender" />
- -->
+
</root>
</log4net>
Modified:
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj?rev=329671&r1=329670&r2=329671&view=diff
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj
(original)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/SampleAppendersApp/cs/src/SampleAppendersApp.csproj
Sun Oct 30 16:18:23 2005
@@ -89,6 +89,11 @@
AssemblyName = "System.Messaging"
HintPath =
"..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Messaging.dll"
/>
+ <Reference
+ Name = "WmiAppender"
+ Project = "{BE56F892-37BA-489C-A91D-F2761FDB96EF}"
+ Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
+ />
</References>
</Build>
<Files>
Propchange: logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Oct 30 16:18:23 2005
@@ -0,0 +1,3 @@
+bin
+doc
+build
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.build
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.build?rev=329671&view=auto
==============================================================================
--- logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.build
(added)
+++ logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.build
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,49 @@
+<?xml version="1.0" ?>
+<!--
+Copyright 2004-2005 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.
+-->
+<project name="wmiappender-cs-example" 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}/SampleAppendersApp.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}/SampleAppendersApp.exe.config" />
+ </target>
+</project>
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.config
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.config?rev=329671&view=auto
==============================================================================
--- logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.config
(added)
+++ logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/nant.config
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,22 @@
+<?xml version="1.0" ?>
+<!--
+Copyright 2004-2005 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.
+-->
+<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>
Propchange: logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Oct 30 16:18:23 2005
@@ -0,0 +1,4 @@
+obj
+*.csproj.user
+bin
+doc
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/AssemblyInfo.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/AssemblyInfo.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/AssemblyInfo.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/AssemblyInfo.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,66 @@
+#region Copyright & License
+//
+// Copyright 2005 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.Appender.WmiAppender")]
+[assembly: AssemblyDescription("The Apache Software Foundation log4net Logging
Framework - WmiAppender")]
+
+#if DEBUG
+[assembly: AssemblyConfiguration("Debug")]
+#else
+[assembly: AssemblyConfiguration("Retail")]
+#endif
+
+[assembly: AssemblyProduct("log4net")]
+[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("")]
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/IWmiBoundEvent.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/IWmiBoundEvent.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/IWmiBoundEvent.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/IWmiBoundEvent.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,52 @@
+#region Copyright & License
+//
+// Copyright 2005 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;
+using System.Management.Instrumentation;
+
+namespace log4net.Appender
+{
+ /// <summary>
+ /// Subclass of <see cref="IEvent"/> for events that need to bind to a
<see cref="LoggingEvent"/>
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// If the <see cref="LoggingEvent"/>.<see
cref="LoggingEvent.MessageObject"/> is
+ /// a <see cref="IWmiBoundEvent"/> then the default behavior of the
<see cref="WmiLayout"/>
+ /// is to call the <see cref="Bind"/> method passing the <see
cref="LoggingEvent"/>.
+ /// This allows the event object to capture additional data from the
<see cref="LoggingEvent"/>
+ /// before it is fired.
+ /// </para>
+ /// </remarks>
+ public interface IWmiBoundEvent : IEvent
+ {
+ /// <summary>
+ /// This method is called before this instance is fired
+ /// </summary>
+ /// <param name="loggingEvent">the <see cref="LoggingEvent"/>
containing the data</param>
+ /// <remarks>
+ /// <para>
+ /// The <see cref="WmiLayout"/> calls this method passing the
<see cref="LoggingEvent"/>
+ /// object. Implementors should capture any required data from
the <paramref name="loggingEvent"/>
+ /// and store it in their instance prior to firing to WMI.
+ /// </para>
+ /// </remarks>
+ void Bind(LoggingEvent loggingEvent);
+ }
+}
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,254 @@
+#region Copyright & License
+//
+// Copyright 2005 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.Threading;
+using log4net.Appender;
+using log4net.Core;
+using System.Management.Instrumentation;
+
+// This is the WMI namespace for event objects in this assembly
+[assembly: Instrumented("root/log4net")]
+
+namespace log4net.Appender
+{
+ /// <summary>
+ /// <see cref="WmiAppender"/> fires instrumented events for each <see
cref="LoggingEvent"/>
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This appender fires Windows Management Instrumentation (WMI) events
for
+ /// each <see cref="LoggingEvent"/>.
+ /// </para>
+ /// <para>
+ /// By default this appender fires <see cref="WmiLoggingEvent"/>
objects, however
+ /// this can be overridden by specifying a custom <see cref="Layout"/>
or by setting
+ /// the <see cref="LoggingEvent"/>.<see
cref="LoggingEvent.MessageObject"/> to an
+ /// <see cref="IEvent"/> instance.
+ /// </para>
+ /// <para>
+ /// This assembly must be registered with WMI. Use the
<c>InstallUtil</c> tool
+ /// shipped with the .NET framework to install this assembly. This will
register
+ /// the <c>root/log4net</c> WMI namespace.
+ /// </para>
+ /// </remarks>
+ public sealed class WmiAppender : IAppender, IOptionHandler
+ {
+ #region Private Instance Fields
+
+ /// <summary>
+ /// The layout of this appender.
+ /// </summary>
+ /// <remarks>
+ /// See <see cref="Layout"/> for more information.
+ /// </remarks>
+ private WmiLayout m_layout;
+
+ /// <summary>
+ /// The name of this appender.
+ /// </summary>
+ /// <remarks>
+ /// See <see cref="Name"/> for more information.
+ /// </remarks>
+ private string m_name;
+
+ /// <summary>
+ /// The level threshold of this appender.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// There is no level threshold filtering by default.
+ /// </para>
+ /// <para>
+ /// See <see cref="Threshold"/> for more information.
+ /// </para>
+ /// </remarks>
+ private Level m_threshold;
+
+ /// <summary>
+ /// It is assumed and enforced that errorHandler is never null.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// It is assumed and enforced that errorHandler is never null.
+ /// </para>
+ /// <para>
+ /// See <see cref="ErrorHandler"/> for more information.
+ /// </para>
+ /// </remarks>
+ private IErrorHandler m_errorHandler = new
log4net.Util.OnlyOnceErrorHandler("WmiAppender");
+
+ #endregion
+
+ #region Public Instance Properties
+
+ /// <summary>
+ /// Gets or sets the name of this appender.
+ /// </summary>
+ /// <value>The name of the appender.</value>
+ /// <remarks>
+ /// <para>
+ /// The name uniquely identifies the appender.
+ /// </para>
+ /// </remarks>
+ public string Name
+ {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the threshold <see cref="Level"/> of this
appender.
+ /// </summary>
+ /// <value>
+ /// The threshold <see cref="Level"/> of the appender.
+ /// </value>
+ /// <remarks>
+ /// <para>
+ /// All log events with lower level than the threshold level
are ignored
+ /// by the appender.
+ /// </para>
+ /// <para>
+ /// In configuration files this option is specified by setting
the
+ /// value of the <see cref="Threshold"/> option to a level
+ /// string, such as "DEBUG", "INFO" and so on.
+ /// </para>
+ /// </remarks>
+ public Level Threshold
+ {
+ get { return m_threshold; }
+ set { m_threshold = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the <see cref="WmiLayout"/> for this appender.
+ /// </summary>
+ /// <value>The layout of the appender.</value>
+ /// <remarks>
+ /// <para>
+ /// The <see cref="WmiLayout"/> to use to format the
+ /// <see cref="LoggingEvent"/> as an <see cref="IEvent"/>.
+ /// </para>
+ /// </remarks>
+ public WmiLayout Layout
+ {
+ get { return m_layout; }
+ set { m_layout = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the <see cref="IErrorHandler"/> for this
appender.
+ /// </summary>
+ /// <value>The <see cref="IErrorHandler"/> of the
appender</value>
+ /// <remarks>
+ /// <para>
+ /// The default value is a <see cref="OnlyOnceErrorHandler"/>.
+ /// </para>
+ /// </remarks>
+ public IErrorHandler ErrorHandler
+ {
+ get { return m_errorHandler; }
+ set
+ {
+ if (value == null)
+ {
+ // We do not throw exception here since
the cause is probably a
+ // bad config file.
+ log4net.Util.LogLog.Warn("WmiAppender:
You have tried to set a null error-handler.");
+ }
+ else
+ {
+ m_errorHandler = value;
+ }
+ }
+ }
+
+ #endregion Public Instance Properties
+
+ /// <summary>
+ /// Activate this appender
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// If a <see cref="Layout"/> has not been specified then this
+ /// method will create a default <see cref="WmiLayout"/>
instance.
+ /// </para>
+ /// </remarks>
+ public void ActivateOptions()
+ {
+ if (m_layout == null)
+ {
+ m_layout = new WmiLayout();
+ }
+ }
+
+ /// <summary>
+ /// Close this appender
+ /// </summary>
+ public void Close()
+ {
+ }
+
+ /// <summary>
+ /// Process a <see cref="LoggingEvent"/>
+ /// </summary>
+ /// <param name="loggingEvent">the <see cref="LoggingEvent"/>
containing the data</param>
+ /// <remarks>
+ /// <para>
+ /// Uses the <see cref="Layout"/> to format the <paramref
name="loggingEvent"/>
+ /// as an <see cref="IEvent"/>. This <see cref="IEvent"/> is
then fired.
+ /// </para>
+ /// </remarks>
+ public void DoAppend(LoggingEvent loggingEvent)
+ {
+ if (loggingEvent == null)
+ {
+ throw new ArgumentNullException("loggingEvent");
+ }
+
+ try
+ {
+ if (IsAsSevereAsThreshold(loggingEvent.Level))
+ {
+ IEvent instrumentationEvent =
m_layout.Format(loggingEvent);
+ if (instrumentationEvent != null)
+ {
+ instrumentationEvent.Fire();
+ }
+ }
+ }
+ catch(Exception ex)
+ {
+ ErrorHandler.Error("Failed in DoAppend", ex);
+ }
+ catch
+ {
+ // Catch handler for non System.Exception types
+ ErrorHandler.Error("Failed in DoAppend (unknown
exception)");
+ }
+ }
+
+ /// <summary>
+ /// Checks if the message level is below this appender's
threshold.
+ /// </summary>
+ private bool IsAsSevereAsThreshold(Level level)
+ {
+ return ((m_threshold == null) || level >= m_threshold);
+ }
+ }
+}
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.csproj
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.csproj?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.csproj
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiAppender.csproj
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,122 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.0.9466"
+ SchemaVersion = "1.0"
+ ProjectGuid = "{BE56F892-37BA-489C-A91D-F2761FDB96EF}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "log4net.Appender.WmiAppender"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "Library"
+ RootNamespace = "log4net.Appender.WmiAppender"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "true"
+ Optimize = "false"
+ OutputPath = "..\bin\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 = "false"
+ Optimize = "true"
+ OutputPath = "..\bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ HintPath =
"..\..\..\..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
+ />
+ <Reference
+ Name = "log4net"
+ AssemblyName = "log4net"
+ HintPath =
"..\..\..\..\..\..\..\build\bin\net\1.0\debug\log4net.dll"
+ />
+ <Reference
+ Name = "System.Configuration.Install"
+ AssemblyName = "System.Configuration.Install"
+ HintPath =
"..\..\..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Configuration.Install.dll"
+ />
+ <Reference
+ Name = "System.Management"
+ AssemblyName = "System.Management"
+ HintPath =
"..\..\..\..\..\..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Management.dll"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "AssemblyInfo.cs"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "AssemblyVersionInfo.cs"
+ Link = "..\..\..\..\..\..\..\src\AssemblyVersionInfo.cs"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "IWmiBoundEvent.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "WmiAppender.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "WmiInstaller.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "WmiLayout.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "WmiLoggingEvent.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiInstaller.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiInstaller.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiInstaller.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiInstaller.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,31 @@
+#region Copyright & License
+//
+// Copyright 2005 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.Management.Instrumentation;
+
+namespace log4net.Appender
+{
+ /// <summary>
+ /// Register this assembly with WMI
+ /// </summary>
+ [System.ComponentModel.RunInstaller(true)]
+ public class WmiInstaller : DefaultManagementProjectInstaller
+ {
+ }
+}
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLayout.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLayout.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLayout.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLayout.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,99 @@
+#region Copyright & License
+//
+// Copyright 2005 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;
+using System.Management.Instrumentation;
+
+namespace log4net.Appender
+{
+ public class WmiLayout
+ {
+ /// <summary>
+ /// Formats a <see cref="LoggingEvent"/> for instrumentation
+ /// </summary>
+ /// <param name="loggingEvent">the <see cref="LoggingEvent"/>
containing the data</param>
+ /// <returns>an instrumentation event that can be
fired</returns>
+ /// <remarks>
+ /// <para>
+ /// If the <see cref="LoggingEvent.MessageObject"/> of the
+ /// <paramref name="loggingEvent" /> is an <see cref="IEvent"/>
then
+ /// that instance is returned. If the instance also implements
the
+ /// <see cref="IWmiBoundEvent"/> interface then the <see
cref="IWmiBoundEvent.Bind"/>
+ /// method will be called on the instance with the <paramref
name="loggingEvent" />
+ /// parameter.
+ /// </para>
+ /// <para>
+ /// If the <see cref="LoggingEvent.MessageObject"/> of the
+ /// <paramref name="loggingEvent" /> is not an <see
cref="IEvent"/>
+ /// then the <see cref="CreateEvent"/> method will be called
+ /// to create an appropriate instrumentation event object.
+ /// </para>
+ /// </remarks>
+ public virtual IEvent Format(LoggingEvent loggingEvent)
+ {
+ // See if the caller gave us an Instrumentation Event
+ IEvent instrumentationEvent =
loggingEvent.MessageObject as IEvent;
+ if (instrumentationEvent != null)
+ {
+ // See if the caller gave us a Bound
Instrumentation Event
+ IWmiBoundEvent boundEvent =
instrumentationEvent as IWmiBoundEvent;
+ if (boundEvent != null)
+ {
+ // Attach the logging event to the
bound instrumentation event
+ boundEvent.Bind(loggingEvent);
+ }
+
+ return instrumentationEvent;
+ }
+
+ // We must create our own IEvent
+ return CreateEvent(loggingEvent);
+ }
+
+ /// <summary>
+ /// Create the <see cref="IEvent"/> instance that should be
fired
+ /// </summary>
+ /// <param name="loggingEvent">the <see cref="LoggingEvent"/>
containing the data</param>
+ /// <returns>an instrumentation event that can be
fired</returns>
+ /// <remarks>
+ /// <para>
+ /// The default implementation of this method creates a <see
cref="WmiLoggingEvent"/>
+ /// instance using the data from the <paramref
name="loggingEvent" />.
+ /// </para>
+ /// <para>
+ /// Subclasses should override this method to return their own
custom
+ /// instrumentation event object.
+ /// </para>
+ /// </remarks>
+ protected virtual IEvent CreateEvent(LoggingEvent loggingEvent)
+ {
+ WmiLoggingEvent wmiEvent = new WmiLoggingEvent();
+
+ wmiEvent.TimeStamp = loggingEvent.TimeStamp;
+ wmiEvent.LoggerName = loggingEvent.LoggerName;
+ wmiEvent.Level = loggingEvent.Level.DisplayName;
+ wmiEvent.Message = loggingEvent.RenderedMessage;
+ wmiEvent.ThreadName = loggingEvent.ThreadName;
+ wmiEvent.ExceptionString =
loggingEvent.GetExceptionString();
+ wmiEvent.Domain = loggingEvent.Domain;
+
+ return wmiEvent;
+ }
+ }
+}
Added:
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLoggingEvent.cs
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLoggingEvent.cs?rev=329671&view=auto
==============================================================================
---
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLoggingEvent.cs
(added)
+++
logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/cs/src/WmiLoggingEvent.cs
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,46 @@
+#region Copyright & License
+//
+// Copyright 2005 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;
+using System.Management.Instrumentation;
+
+namespace log4net.Appender
+{
+ /// <summary>
+ /// The default instrumented event raised by the <see
cref="WmiAppender"/>
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This is the default event fired by the <see cref="WmiAppender"/>.
+ /// To fire a custom event set the <see cref="WmiAppender.Layout"/> to a
+ /// subclass of <see cref="WmiLayout"/> that overrides the <see
cref="WmiLayout.CreateEvent"/>
+ /// method.
+ /// </para>
+ /// </remarks>
+ public class WmiLoggingEvent : BaseEvent
+ {
+ public DateTime TimeStamp;
+ public string LoggerName;
+ public string Level;
+ public string Message;
+ public string ThreadName;
+ public string ExceptionString;
+ public string Domain;
+ }
+}
Added: logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.build
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.build?rev=329671&view=auto
==============================================================================
--- logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.build
(added)
+++ logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.build Sun
Oct 30 16:18:23 2005
@@ -0,0 +1,28 @@
+<?xml version="1.0" ?>
+<!--
+Copyright 2004-2005 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.
+-->
+<project name="wmiappender-example" default="compile"
xmlnds="http://tempuri.org/nant-vs.xsd">
+ <!-- compile ConsoleApp example -->
+ <target name="compile" description="Builds WmiAppender example">
+ <nant target="compile">
+ <buildfiles>
+ <include name="*/nant.build" />
+ <!-- exclude current build file -->
+ <exclude name="exclude.build" />
+ </buildfiles>
+ </nant>
+ </target>
+</project>
Added: logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.config
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.config?rev=329671&view=auto
==============================================================================
--- logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.config
(added)
+++ logging/log4net/trunk/examples/net/1.0/Appenders/WmiAppender/nant.config
Sun Oct 30 16:18:23 2005
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!--
+Copyright 2004-2005 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.
+-->
+<project name="configuration" xmlnds="http://tempuri.org/nant-vs.xsd">
+ <!-- Include parent configuration file -->
+ <include buildfile="../nant.config" />
+</project>
Modified: logging/log4net/trunk/examples/net/1.0/cs-examples.sln
URL:
http://svn.apache.org/viewcvs/logging/log4net/trunk/examples/net/1.0/cs-examples.sln?rev=329671&r1=329670&r2=329671&view=diff
==============================================================================
--- logging/log4net/trunk/examples/net/1.0/cs-examples.sln (original)
+++ logging/log4net/trunk/examples/net/1.0/cs-examples.sln Sun Oct 30 16:18:23
2005
@@ -25,6 +25,8 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleLayoutsApp",
"Layouts\SampleLayoutsApp\cs\src\SampleLayoutsApp.csproj",
"{CD7A8094-D383-46BC-A75D-9F65F746E24F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WmiAppender",
"Appenders\WmiAppender\cs\src\WmiAppender.csproj",
"{BE56F892-37BA-489C-A91D-F2761FDB96EF}"
+EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
@@ -85,6 +87,10 @@
{CD7A8094-D383-46BC-A75D-9F65F746E24F}.Debug.Build.0 =
Debug|.NET
{CD7A8094-D383-46BC-A75D-9F65F746E24F}.Release.ActiveCfg =
Release|.NET
{CD7A8094-D383-46BC-A75D-9F65F746E24F}.Release.Build.0 =
Release|.NET
+ {BE56F892-37BA-489C-A91D-F2761FDB96EF}.Debug.ActiveCfg =
Debug|.NET
+ {BE56F892-37BA-489C-A91D-F2761FDB96EF}.Debug.Build.0 =
Debug|.NET
+ {BE56F892-37BA-489C-A91D-F2761FDB96EF}.Release.ActiveCfg =
Release|.NET
+ {BE56F892-37BA-489C-A91D-F2761FDB96EF}.Release.Build.0 =
Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection