protected override void Publish(EventTypeOption eventType, List <TypedItem> properties) { bool b = false; if (passthroughs.Contains(eventType)) { b = true; } TraceEventTypeOption option = TraceEventTypeOption.Verbose; StringBuilder sb = new StringBuilder(); foreach (var prop in properties) { if (prop.Value != null) { if (prop.Key.Equals(XFConstants.EventWriter.ErrorSeverity) && Enum.TryParse <TraceEventTypeOption>(prop.Value.ToString(), out option)) { b = true; } sb.AppendLine(String.Format("{0}\t:\t{1}", prop.Key, prop.Value.ToString())); } } if (!String.IsNullOrWhiteSpace(eXtensibleConfig.LogSource) && !EventLog.SourceExists(eXtensibleConfig.LogSource)) { try { EventLog.CreateEventSource(eXtensibleConfig.LogSource, LogName); } catch (Exception) { b = false; } } if (b) { if (option == TraceEventTypeOption.Critical | option == TraceEventTypeOption.Error) { Publish(EventLogEntryType.Error, sb.ToString()); } else if (option == TraceEventTypeOption.Warning) { Publish(EventLogEntryType.Warning, sb.ToString()); } else { Publish(EventLogEntryType.Information, sb.ToString()); } } }
static eXtensibleConfig() { try { string configfilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string configFolder = Path.GetDirectoryName(configfilepath); ModelPlugins = configFolder + "\\" + "model"; ModelDataGatewayPlugins = configFolder + "\\" + "mdg"; ServicePlugins = configFolder + "\\" + "services"; RemoteProcedureCallPlugins = configFolder + "\\" + "rpc"; DbConfigs = configFolder + "\\" + "db.configs"; BaseDirectory = configFolder; var configfilemap = new ExeConfigurationFileMap() { ExeConfigFilename = configfilepath }; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configfilemap, ConfigurationUserLevel.None); eXtensibleFrameworkSection section = config.Sections[XFConstants.Config.SectionName] as eXtensibleFrameworkSection; if (section != null) { string candidateContext = ConfigurationManager.AppSettings[XFConstants.Application.Config.ApplicationKey]; string candidateZone = ConfigurationManager.AppSettings[XFConstants.Application.Config.ZoneKey]; //string candidateLogging = ConfigurationManager.AppSettings[XFConstants.Application.Config.LoggingStrategyKey]; //string candidateLoggingSeverity = ConfigurationManager.AppSettings[XFConstants.Application.Config.LoggingSeverityKey]; string candidateConnectionStringKey = ConfigurationManager.AppSettings[XFConstants.Application.Config.ConnectionStringKey]; string candidateLogSource = ConfigurationManager.AppSettings[XFConstants.Application.Config.LogSourceKey]; string candidateBigDataUrl = ConfigurationManager.AppSettings[XFConstants.Application.Config.BigDataUrlKey]; string candidateServiceToken = ConfigurationManager.AppSettings[XFConstants.Application.Config.ServiceTokenKey]; string candidateInstance = ConfigurationManager.AppSettings[XFConstants.Application.Config.InstanceIdentifierKey]; string candidateInfer = ConfigurationManager.AppSettings[XFConstants.Application.Config.InferKey]; ZoneOption option; if (Enum.TryParse <ZoneOption>(section.Zone, true, out option)) { Zone = option.ToString(); } else if (!String.IsNullOrEmpty(candidateZone) && Enum.TryParse <ZoneOption>(candidateZone, true, out option)) { Zone = option.ToString(); } else { Zone = ZoneOption.Development.ToString(); } if (!String.IsNullOrEmpty(section.Context)) { Context = section.Context; } else { Context = !String.IsNullOrEmpty(candidateContext) ? candidateContext : XFConstants.Application.DefaultAppplicationKey; } if (!String.IsNullOrEmpty(section.InstanceIdentifier)) { if (section.InstanceIdentifier.Equals("machine", StringComparison.OrdinalIgnoreCase)) { InstanceIdentifier = Environment.MachineName.ToLower(); } else { InstanceIdentifier = section.InstanceIdentifier; } } else if (!String.IsNullOrEmpty(candidateInfer)) { if (candidateInfer.Equals("machine", StringComparison.OrdinalIgnoreCase)) { InstanceIdentifier = Environment.MachineName.ToLower(); } else { InstanceIdentifier = candidateInfer; } InstanceIdentifier = !String.IsNullOrEmpty(candidateInstance) ? candidateInstance : new Guid().ToString(); } else { InstanceIdentifier = Environment.MachineName.ToLower(); } bool infer; if (!String.IsNullOrWhiteSpace(candidateInfer) && Boolean.TryParse(candidateInfer, out infer)) { Infer = infer; } else { Infer = false; } bool inform = false; var found = section.Elements.GetForLoggingMode(section.LoggingKey); LoggingStrategyOption loggingStrategy; if (Enum.TryParse <LoggingStrategyOption>(found.LoggingStrategy, true, out loggingStrategy)) { LoggingStrategy = loggingStrategy; inform = found.Inform; } else { LoggingStrategy = LoggingStrategyOption.Silent; } Inform = inform; TraceEventTypeOption eventType; if (Enum.TryParse <TraceEventTypeOption>(found.PublishSeverity, true, out eventType)) { LoggingSeverity = eventType; } else { LoggingSeverity = TraceEventTypeOption.Verbose; } if (!String.IsNullOrEmpty(section.LogSource)) { LogSource = section.LogSource; } else if (!String.IsNullOrEmpty(candidateLogSource)) { LogSource = candidateLogSource; } else { LogSource = XFConstants.Config.DefaultLogSource; } if (!String.IsNullOrEmpty(section.BigDataUrl)) { BigDataUrl = section.BigDataUrl; } else if (!String.IsNullOrEmpty(candidateBigDataUrl)) { BigDataUrl = candidateBigDataUrl; } else { // } if (!String.IsNullOrEmpty(section.ServiceToken)) { ServiceToken = section.ServiceToken; } else if (!String.IsNullOrEmpty(candidateServiceToken)) { ServiceToken = candidateServiceToken; } else { ServiceToken = XFConstants.Config.DefaultServiceToken; } if (!String.IsNullOrEmpty(candidateConnectionStringKey)) { ConnectionStringKey = candidateConnectionStringKey; } CaptureMetrics = section.CaptureMetrics; IsAsync = false; AppUserIdentity = XFConstants.Config.AppUserIdentityParamName; DefaultLoggingCategory = XFConstants.Category.General; ApiRoot = XFConstants.Api.DefaultRoot; ApiErrors = XFConstants.Api.DefaultErrorsEndpoint; ApiEvents = XFConstants.Api.DefaultEventsEndpoint; ApiStatii = XFConstants.Api.DefaultStatiiEndpoint; ApiMetrics = XFConstants.Api.DefaultMetricsEndpoint; ApiAlerts = XFConstants.Api.DefaultAlertsEndpoint; ApiTasks = XFConstants.Api.DefaultTasksEndpoint; ApiKpi = XFConstants.Api.DefaultKpiEndpoint; ApiCustom = XFConstants.Api.DefaultCustomEndpoint; } else { section = new eXtensibleFrameworkSection(); Zone = section.Zone = XFConstants.ZONE.Development; Context = section.Context = XFConstants.Config.DefaultApplicationKey; IsAsync = section.IsAsync = false; InstanceIdentifier = section.InstanceIdentifier = String.Empty; AppUserIdentity = section.UserIdentityParamName = XFConstants.Config.AppUserIdentityParamName; DefaultLoggingCategory = XFConstants.Category.General; LoggingStrategy = LoggingStrategyOption.WindowsEventLog; LoggingSeverity = TraceEventTypeOption.Verbose; LogSource = XFConstants.Config.DefaultLogSource; ServiceToken = XFConstants.Config.DefaultServiceToken; Infer = false; } } catch (Exception ex) { Exception = ex.Message; Zone = XFConstants.Config.DefaultZone; DataPlugins = XFConstants.Config.DATAACCESSCONTEXTFOLDERPATH; DefaultLoggingCategory = XFConstants.Category.General; LoggingStrategyOption option; if (Enum.TryParse <LoggingStrategyOption>(XFConstants.Config.DefaultLoggingStrategy, true, out option)) { LoggingStrategy = option; } else { LoggingStrategy = LoggingStrategyOption.XFTool; } TraceEventTypeOption severity; if (Enum.TryParse <TraceEventTypeOption>(XFConstants.Config.DefaultPublishingSeverity, true, out severity)) { LoggingSeverity = severity; } else { LoggingSeverity = TraceEventTypeOption.Verbose; } Infer = false; LogSource = XFConstants.Config.DefaultLogSource; ServiceToken = XFConstants.Config.DefaultServiceToken; ApiRoot = XFConstants.Api.DefaultRoot; ApiErrors = XFConstants.Api.DefaultErrorsEndpoint; ApiEvents = XFConstants.Api.DefaultEventsEndpoint; ApiStatii = XFConstants.Api.DefaultStatiiEndpoint; ApiMetrics = XFConstants.Api.DefaultMetricsEndpoint; ApiAlerts = XFConstants.Api.DefaultAlertsEndpoint; ApiTasks = XFConstants.Api.DefaultTasksEndpoint; ApiKpi = XFConstants.Api.DefaultKpiEndpoint; ApiCustom = XFConstants.Api.DefaultCustomEndpoint; } finally { } _ExtendedProperties.Add(XFConstants.Context.ZONE, Zone); _ExtendedProperties.Add(XFConstants.Context.Application, Context); _ExtendedProperties.Add(XFConstants.Context.INSTANCEIDENTIFIER, InstanceIdentifier); }
public static bool IsSeverityAtLeast(TraceEventTypeOption option) { return(LoggingSeverity >= option); }