Exemplo n.º 1
0
        //
        // FindProvidersByLogForWildcardPatterns helper.
        // Finds all providers whose names match wildcard patterns in 'providerPatterns' argument.   
        // For each non-matched pattern, a non-terminating error is written.
        // The results are added to _providersByLogMap dictionary (keyed by log names to which these providers write).  
        //
        private void FindProvidersByLogForWildcardPatterns(EventLogSession eventLogSession, IEnumerable<string> providerPatterns)
        {
            _providersByLogMap.Clear();

            foreach (string provPattern in providerPatterns)
            {
                bool bMatched = false;
                foreach (string provName in eventLogSession.GetProviderNames())
                {
                    WildcardPattern wildProvPattern = new WildcardPattern(provPattern, WildcardOptions.IgnoreCase);

                    if (((!WildcardPattern.ContainsWildcardCharacters(provPattern))
                      && (provPattern.Equals(provName, StringComparison.CurrentCultureIgnoreCase)))
                      ||
                      (wildProvPattern.IsMatch(provName)))
                    {
                        WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Found matching provider: {0}", provName));
                        AddLogsForProviderToInternalMap(eventLogSession, provName);
                        bMatched = true;
                    }
                }
                if (!bMatched)
                {
                    string msg = _resourceMgr.GetString("NoMatchingProvidersFound");
                    Exception exc = new Exception(string.Format(CultureInfo.InvariantCulture, msg, _computerName, provPattern));
                    WriteError(new ErrorRecord(exc, "NoMatchingProvidersFound", ErrorCategory.ObjectNotFound, provPattern));
                }
            }
        }
Exemplo n.º 2
0
        private void LoadProvider()
        {
            if (string.IsNullOrEmpty(_providerName))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderNotSpecified")), "ProviderName");
            }

            using (EventLogSession session = new EventLogSession())
            {
                foreach (string providerName in session.GetProviderNames())
                {
                    if (string.Equals(providerName, _providerName, StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            _providerMetadata = new ProviderMetadata(providerName);
                        }
                        catch (EventLogException exc)
                        {
                            string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderMetadataUnavailable"), providerName, exc.Message);
                            throw new Exception(msg, exc);
                        }
                        break;
                    }
                }
            }

            if (_providerMetadata == null)
            {
                string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoProviderFound"), _providerName);
                throw new ArgumentException(msg);
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            int exitCode = 0;
            bool listProviders = true;
            String providerName = "";

            try
            {
                //
                // Get command line information.
                //
                if (args.Length > 0)
                {
                    if (args[0] == "/?" || args[0] == "-?")
                    {
                        Console.WriteLine(
                            "Usage: ProviderMetadata [<providerName>]\n" +
                            "<providerName> is the name of an existing event provider\n" +
                            "When <providerName> is not specified, the names of the first 20 providers will be listed.\n" +
                            "EXAMPLE: ProviderMetadata.exe \"Application Error\"." );
                        Environment.Exit(0);
                    }
                    else
                    {
                        providerName = args[0];
                        listProviders = false;
                    }
                }

               if (listProviders)
               {
                    //
                    // List the first 20 providers.
                    //

                    EventLogSession session = new EventLogSession();
                    int count = 0;
                    foreach (string provName in session.GetProviderNames())
                    {
                        Console.WriteLine("\t{0}", provName);
                        if (++count >= 20)
                        {
                            break;
                        }
                    }
               }
               else
               {
                   //
                   // Read the specified provider's metadata.
                   //

                   ProviderMetadata providerMetadata = new ProviderMetadata(providerName);
                   Console.WriteLine("MessageFilePath for provider '{0}' is '{1}'.", providerName, providerMetadata.MessageFilePath);

                   //
                   // Read the provider's event metadata.
                   //

                   Console.WriteLine("Provider '{0}' contains event metadata for the following event ids:", providerName);
                   foreach (EventMetadata eventMetadata in providerMetadata.Events)
                   {
                       Console.WriteLine("\t{0}", eventMetadata.Id);
                   }
               }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
                exitCode = 1;
            }

            Environment.Exit(exitCode);
        }
Exemplo n.º 4
0
 private void FindProvidersByLogForWildcardPatterns(EventLogSession eventLogSession, IEnumerable<string> providerPatterns)
 {
     this._providersByLogMap.Clear();
     foreach (string str in providerPatterns)
     {
         bool flag = false;
         foreach (string str2 in eventLogSession.GetProviderNames())
         {
             WildcardPattern pattern = new WildcardPattern(str, WildcardOptions.IgnoreCase);
             if ((!WildcardPattern.ContainsWildcardCharacters(str) && str.Equals(str2, StringComparison.CurrentCultureIgnoreCase)) || pattern.IsMatch(str2))
             {
                 base.WriteVerbose(string.Format(CultureInfo.InvariantCulture, "Found matching provider: {0}", new object[] { str2 }));
                 this.AddLogsForProviderToInternalMap(eventLogSession, str2);
                 flag = true;
             }
         }
         if (!flag)
         {
             string format = this._resourceMgr.GetString("NoMatchingProvidersFound");
             Exception exception = new Exception(string.Format(CultureInfo.InvariantCulture, format, new object[] { this._computerName, str }));
             base.WriteError(new ErrorRecord(exception, "NoMatchingProvidersFound", ErrorCategory.ObjectNotFound, str));
         }
     }
 }
Exemplo n.º 5
0
 private void LoadProvider()
 {
     if (string.IsNullOrEmpty(this.providerName))
     {
         throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("ProviderNotSpecified"), new object[0]), "ProviderName");
     }
     using (EventLogSession session = new EventLogSession())
     {
         foreach (string str in session.GetProviderNames())
         {
             if (string.Equals(str, this.providerName, StringComparison.OrdinalIgnoreCase))
             {
                 try
                 {
                     this.providerMetadata = new ProviderMetadata(str);
                     goto Label_00D2;
                 }
                 catch (EventLogException exception)
                 {
                     throw new Exception(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("ProviderMetadataUnavailable"), new object[] { str, exception.Message }), exception);
                 }
             }
         }
     }
 Label_00D2:
     if (this.providerMetadata == null)
     {
         throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, this._resourceMgr.GetString("NoProviderFound"), new object[] { this.providerName }));
     }
 }