From ff5051a8d15a902a154ec1d129a204f6cff3da0a Mon Sep 17 00:00:00 2001 From: Phillip Clark Date: Wed, 16 Jun 2010 17:34:22 +0000 Subject: [PATCH] Added DefaultEmitterName to config file and hander. git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-dotnet/trunk@486 a2f82657-cdd2-4550-bd36-68a8e7111808 --- Org.Lwes/Config/LwesConfigurationSection.cs | 14 +++ Org.Lwes/Constants.cs | 2 +- Org.Lwes/Emitter/EventEmitter.cs | 3 +- Org.Lwes/LwesTraceListener.cs | 48 ++++----- Org.Lwes/Org.Lwes.csproj | 1 + Org.Lwes/Trace/TraceMessage.esf | 22 ++++ .../Lwes-test-listener-console/Program.cs | 111 ++++++++++++++++++++- bin/UpdateWixProjectWithVersion.exe | Bin 8704 -> 8704 bytes bin/UpdateWixProjectWithVersion.pdb | Bin 15872 -> 15872 bytes 9 files changed, 171 insertions(+), 30 deletions(-) create mode 100644 Org.Lwes/Trace/TraceMessage.esf diff --git a/Org.Lwes/Config/LwesConfigurationSection.cs b/Org.Lwes/Config/LwesConfigurationSection.cs index fe17791..c224f7a 100644 --- a/Org.Lwes/Config/LwesConfigurationSection.cs +++ b/Org.Lwes/Config/LwesConfigurationSection.cs @@ -58,6 +58,8 @@ namespace Org.Lwes.Config /// public const string PropertyName_templateDBs = "templateDBs"; + public const string PropertyName_defaultEmitter = "defaultEmitter"; + /// /// Section name used for configuring the Light Weight Event System. /// @@ -68,6 +70,18 @@ namespace Org.Lwes.Config #region Properties /// + /// Indicates the name of the emitter used as default. + /// + [ConfigurationProperty(PropertyName_defaultEmitter, + IsRequired = false, + DefaultValue = Constants.CDefaultEventEmitterConfigName)] + public string DefaultEmitterName + { + get { return (string)this[PropertyName_defaultEmitter]; } + set { this[PropertyName_defaultEmitter] = value; } + } + + /// /// Indicates the length of buffers used for event buffering. /// [ConfigurationProperty(PropertyName_bufferAllocationLength diff --git a/Org.Lwes/Constants.cs b/Org.Lwes/Constants.cs index a048e5a..8422faa 100644 --- a/Org.Lwes/Constants.cs +++ b/Org.Lwes/Constants.cs @@ -41,7 +41,7 @@ namespace Org.Lwes /// /// Name identifying the default event emitter in the configuration file. /// - public static readonly string DefaultEventEmitterConfigName = "default"; + public const string CDefaultEventEmitterConfigName = "default"; /// /// IoC container key for the default IEventEmitter instance. diff --git a/Org.Lwes/Emitter/EventEmitter.cs b/Org.Lwes/Emitter/EventEmitter.cs index a5dec62..bc508c6 100644 --- a/Org.Lwes/Emitter/EventEmitter.cs +++ b/Org.Lwes/Emitter/EventEmitter.cs @@ -51,7 +51,8 @@ namespace Org.Lwes.Emitter if (!IoCAdapter.TryCreateFromIoC(Constants.DefaultEventEmitterContainerKey, out result)) { // Either there isn't a default event template defined in the IoC container // or there isn't an IoC container in use... fall back to configuration section. - result = CreateFromConfig(Constants.DefaultEventEmitterConfigName); + var def = LwesConfigurationSection.Current.DefaultEmitterName; + result = CreateFromConfig(def); } if (result == null) { // Not in IoC and not configured; fallback to programmatic default. diff --git a/Org.Lwes/LwesTraceListener.cs b/Org.Lwes/LwesTraceListener.cs index 645038c..6ae071d 100644 --- a/Org.Lwes/LwesTraceListener.cs +++ b/Org.Lwes/LwesTraceListener.cs @@ -225,12 +225,12 @@ namespace Org.Lwes int port = (Port == 0) ? Constants.CDefaultMulticastPort : Port; int ttl = (MulticastTimeToLive == 0) ? Constants.CDefaultMulticastTtl : MulticastTimeToLive; emitter.InitializeAll(SupportedEncoding.Default, - #if DEBUG - true, - #else +#if DEBUG + true, +#else false, - #endif - EventTemplateDB.CreateDefault(), +#endif + EventTemplateDB.CreateDefault(), addy, port, ttl, @@ -277,10 +277,10 @@ namespace Org.Lwes public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) { Event ev = Emitter.CreateEvent(EventName_TraceMessage); - ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); - ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); - ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); - ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); + ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); + ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); + ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); + ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); if (eventType <= TraceEventType.Warning) { ev.SetValue(AttributeName_Callstack, Convert.ToString(eventCache.Callstack)); @@ -288,8 +288,8 @@ namespace Org.Lwes } ev.SetValue(AttributeName_Source, source); ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); - ev.SetValue(AttributeName_ID, id); - ev.SetValue(AttributeName_Data, Convert.ToString(data)); + ev.SetValue(AttributeName_ID, id); + ev.SetValue(AttributeName_Data, Convert.ToString(data)); _emitter.Emit(ev); } @@ -307,18 +307,18 @@ namespace Org.Lwes public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data) { Event ev = Emitter.CreateEvent(EventName_TraceMessage); - ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); - ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); - ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); - ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); + ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); + ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); + ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); + ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); if (eventType <= TraceEventType.Warning) { ev.SetValue(AttributeName_Callstack, Convert.ToString(eventCache.Callstack)); ev.SetValue(AttributeName_LogicalOperationStack, Convert.ToString(eventCache.LogicalOperationStack)); } ev.SetValue(AttributeName_Source, source); - ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); - ev.SetValue(AttributeName_ID, id); + ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); + ev.SetValue(AttributeName_ID, id); for (int i = 0; i < data.Length; i++) { ev.SetValue(String.Concat(AttributeName_Data, "_", i), Convert.ToString(data[i])); @@ -339,10 +339,10 @@ namespace Org.Lwes public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id) { Event ev = Emitter.CreateEvent(EventName_TraceMessage); - ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); - ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); - ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); - ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); + ev.SetValue(AttributeName_ProcessId, eventCache.ProcessId); + ev.SetValue(AttributeName_ThreadId, eventCache.ThreadId); + ev.SetValue(AttributeName_DateTime, eventCache.DateTime.ToString("u")); + ev.SetValue(AttributeName_Timestamp, eventCache.Timestamp); if (eventType <= TraceEventType.Warning) { ev.SetValue(AttributeName_Callstack, Convert.ToString(eventCache.Callstack)); @@ -350,7 +350,7 @@ namespace Org.Lwes } ev.SetValue(AttributeName_Source, source); ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); - ev.SetValue(AttributeName_ID, id); + ev.SetValue(AttributeName_ID, id); _emitter.Emit(ev); } @@ -377,7 +377,7 @@ namespace Org.Lwes if (eventType <= TraceEventType.Warning) { ev.SetValue(AttributeName_Callstack, Convert.ToString(eventCache.Callstack)); - ev.SetValue(AttributeName_LogicalOperationStack, Convert.ToString(eventCache.LogicalOperationStack)); + ev.SetValue(AttributeName_LogicalOperationStack, Convert.ToString(eventCache.LogicalOperationStack)); } ev.SetValue(AttributeName_Source, source); ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); @@ -407,7 +407,7 @@ namespace Org.Lwes if (eventType <= TraceEventType.Warning) { ev.SetValue(AttributeName_Callstack, Convert.ToString(eventCache.Callstack)); - ev.SetValue(AttributeName_LogicalOperationStack, Convert.ToString(eventCache.LogicalOperationStack)); + ev.SetValue(AttributeName_LogicalOperationStack, Convert.ToString(eventCache.LogicalOperationStack)); } ev.SetValue(AttributeName_Source, source); ev.SetValue(AttributeName_TraceEventType, eventType.ToString()); diff --git a/Org.Lwes/Org.Lwes.csproj b/Org.Lwes/Org.Lwes.csproj index cd4f0cb..b9e347c 100644 --- a/Org.Lwes/Org.Lwes.csproj +++ b/Org.Lwes/Org.Lwes.csproj @@ -140,6 +140,7 @@ AssemblyInfo.version.cs +