Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LINQ to parse EventLog Query [modified]

LINQ to parse EventLog Query [modified]

Scheduled Pinned Locked Moved C#
csharpdatabaselinqhelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi All, I want LINQ query to retrieve records from eventlog viewer with like operator. Is there any LIKE operator in LINQ? please help me. Regards, Sunil G.

    modified on Wednesday, February 3, 2010 7:25 AM

    R P P 3 Replies Last reply
    0
    • L Lost User

      Hi All, I want LINQ query to retrieve records from eventlog viewer with like operator. Is there any LIKE operator in LINQ? please help me. Regards, Sunil G.

      modified on Wednesday, February 3, 2010 7:25 AM

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      You could just use String.StartsWith()[^]. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • L Lost User

        Hi All, I want LINQ query to retrieve records from eventlog viewer with like operator. Is there any LIKE operator in LINQ? please help me. Regards, Sunil G.

        modified on Wednesday, February 3, 2010 7:25 AM

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Bear in mind that the event log entries are just a collection, you can retrieve items from it using something like the following:

        var item = from EventLogEntry p in EventLog.GetEventLogs().First().Entries
        where p.Message.Contains("Online")
        select new { Id = p.InstanceId, Message = p.Message };

        In this sample, I'm just picking from the first event log - you would probably want to refine this to find the log you are interested in explicitly. The Contains method is the closest you'll get to the Like operator.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • L Lost User

          Hi All, I want LINQ query to retrieve records from eventlog viewer with like operator. Is there any LIKE operator in LINQ? please help me. Regards, Sunil G.

          modified on Wednesday, February 3, 2010 7:25 AM

          P Offline
          P Offline
          Palash Biswas
          wrote on last edited by
          #4

          You can use the below code if you using LINQ to Objects

          private void button1_Click(object sender, EventArgs e)
          {
          List<Customer> customers = new List<Customer>();
          customers.Add(new Customer { CustomerID = "A12I", CustomerName = "Palash" });
          customers.Add(new Customer { CustomerID = "B20G", CustomerName = "Ankesh" });
          customers.Add(new Customer { CustomerID = "A100I", CustomerName = "Subhadip" });
          customers.Add(new Customer { CustomerID = "C12G", CustomerName = "Namita" });
          var result = (from c in customers
          where c.CustomerID.StartsWith("A") && c.CustomerID.EndsWith("I")
          select c).ToList();
          foreach (Customer c in result)
          {
          MessageBox.Show(c.CustomerName);
          }
          }

          }
          
          public class Customer
          {
              public string CustomerID;
              public string CustomerName;
          }
          

          for Search A%I . In case Of Search %I% you can use String Contains method to do that In Case of LINQ to SQL You can Use the Syntax like

          var result = (from c in db.Customers
          where System.Data.Linq.SqlClient.SqlMethods.Like(c.CustomerID, "A%I")
          select c).ToList();

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups