Custom Event Logging / Shared Class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CJ Taylor

    Custom Event Logging / Shared Class

    Hey all,

    This is probably a dumb question, but still feeling a little strange from
    Labor day festiviities. Anyways,

    I want a shared sub, at least something that is easy to call from any one of
    my classes within the scope of my project (or that which inherits/imports
    this class).

    Basically, want them to be able to call a sub defined as

    Public Shared Sub LogEvent (sender as object, e as
    MWC.BCTransfer. Logger.LogEvent Args)

    now tihs is fine... but if the UI is active, I want it to push information
    to a listview I have.

    Now I can call the LogEvent routine fine, but if I try to access a UI
    function, I obviuosly can't.

    How do I get around this?

    Thanks,
    CJ


  • Benny Mathew

    #2
    Re: Custom Event Logging / Shared Class

    Hi,
    You cannot call non shared members of a class from the shared method
    without making an instance of it and then calling it on that instance.

    Cheers
    Benny


    CJ Taylor wrote:
    [color=blue]
    > Hey all,
    >
    > This is probably a dumb question, but still feeling a little strange from
    > Labor day festiviities. Anyways,
    >
    > I want a shared sub, at least something that is easy to call from any one of
    > my classes within the scope of my project (or that which inherits/imports
    > this class).
    >
    > Basically, want them to be able to call a sub defined as
    >
    > Public Shared Sub LogEvent (sender as object, e as
    > MWC.BCTransfer. Logger.LogEvent Args)
    >
    > now tihs is fine... but if the UI is active, I want it to push information
    > to a listview I have.
    >
    > Now I can call the LogEvent routine fine, but if I try to access a UI
    > function, I obviuosly can't.
    >
    > How do I get around this?
    >
    > Thanks,
    > CJ
    >
    >[/color]

    Comment

    • CJ Taylor

      #3
      Re: Custom Event Logging / Shared Class

      Thanks benny,

      I was sure on that part, but does anyone know of a method to do this? Like
      to write a good / simple event logger?

      I suppose I could do inherited stuff, but I was hoping for something
      simplier.

      Thanks,
      CJ
      "Benny Mathew" <benny@mvps.org > wrote in message
      news:%23yZ5QkVc DHA.1492@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Hi,
      > You cannot call non shared members of a class from the shared method
      > without making an instance of it and then calling it on that instance.
      >
      > Cheers
      > Benny
      >
      >
      > CJ Taylor wrote:
      >[color=green]
      > > Hey all,
      > >
      > > This is probably a dumb question, but still feeling a little strange[/color][/color]
      from[color=blue][color=green]
      > > Labor day festiviities. Anyways,
      > >
      > > I want a shared sub, at least something that is easy to call from any[/color][/color]
      one of[color=blue][color=green]
      > > my classes within the scope of my project (or that which[/color][/color]
      inherits/imports[color=blue][color=green]
      > > this class).
      > >
      > > Basically, want them to be able to call a sub defined as
      > >
      > > Public Shared Sub LogEvent (sender as object, e as
      > > MWC.BCTransfer. Logger.LogEvent Args)
      > >
      > > now tihs is fine... but if the UI is active, I want it to push[/color][/color]
      information[color=blue][color=green]
      > > to a listview I have.
      > >
      > > Now I can call the LogEvent routine fine, but if I try to access a UI
      > > function, I obviuosly can't.
      > >
      > > How do I get around this?
      > >
      > > Thanks,
      > > CJ
      > >
      > >[/color]
      >[/color]


      Comment

      • Jeremy Cowles

        #4
        Re: Custom Event Logging / Shared Class

        > Now I can call the LogEvent routine fine, but if I try to access a UI[color=blue]
        > function, I obviuosly can't.
        >
        > How do I get around this?[/color]

        Why would you want to? That's the real question... The fact that you hit a
        wall is just an indicator that you are trying to break the rules of "good
        OOP" design (or whatever). You have:

        Logger.Log(o, e) - Takes in a source object, logs an event

        This is the object you use for storing information, I would say that you are
        trying to mix your data/information with your UI, and this is generally bad.
        The alternative would be to log the information (storing it in however you
        want), and then provide access to that log data via some shared Property or
        Method, then your UI is still independant of your information:

        Public Class Logger
        Public Shared Sub LogEvent( sender as Object, e as LogEventArgs)
        ...
        RaiseEvent LogAdded(...)
        End Sub

        Public Shared Property EntryCount as Integer
        Public Default ReadOnly Shared Property Item(index as Integer) as
        LogObject
        End Class

        Now when your list updates, it can just read the Item property of the
        logger:

        '// Client Code
        ListView.BeginU pdate
        ListView.Items. Clear

        For I as Integer = 0 to Logger.EntryCou nt
        ListView.Items. Add ( log )
        Next

        ListView.EndUpd ate


        What do you think?

        ~
        Jeremy

        Comment

        • CJ Taylor

          #5
          Re: Custom Event Logging / Shared Class

          Perfect Jeremy,

          That was the goal, I was just struggling a little this morning to think
          about how I wanted to do it...

          Also, I think that because I'm doing this within a separated DLL, I'll do it
          kinda like how MSCOMCTL was done in the past, where I will raise my own
          dialogs as well, kinda like a built in UI to the DLL so its uniform, but
          also make the Loglist (XML Data of the logged events) public readonly that
          way other applications can get a handler on it, and add an event like you
          said to say when its raised, another UI that is wrapping that DLL can be
          notified, and therefore, pull updated event data...

          I could see where this could become cumbersome (especially if you had large
          amounts of Event Data), so maybe even add a property about 'last event
          added." or something...

          I don't know... thoughts?

          -CJ
          "Jeremy Cowles" <jeremy.cowle s[nosp@m]asifl.com> wrote in message
          news:uu25b.24$y _6.9591@twister .tampabay.rr.co m...[color=blue][color=green]
          > > Now I can call the LogEvent routine fine, but if I try to access a UI
          > > function, I obviuosly can't.
          > >
          > > How do I get around this?[/color]
          >
          > Why would you want to? That's the real question... The fact that you hit[/color]
          a[color=blue]
          > wall is just an indicator that you are trying to break the rules of "good
          > OOP" design (or whatever). You have:
          >
          > Logger.Log(o, e) - Takes in a source object, logs an event
          >
          > This is the object you use for storing information, I would say that you[/color]
          are[color=blue]
          > trying to mix your data/information with your UI, and this is generally[/color]
          bad.[color=blue]
          > The alternative would be to log the information (storing it in however you
          > want), and then provide access to that log data via some shared Property[/color]
          or[color=blue]
          > Method, then your UI is still independant of your information:
          >
          > Public Class Logger
          > Public Shared Sub LogEvent( sender as Object, e as LogEventArgs)
          > ...
          > RaiseEvent LogAdded(...)
          > End Sub
          >
          > Public Shared Property EntryCount as Integer
          > Public Default ReadOnly Shared Property Item(index as Integer) as
          > LogObject
          > End Class
          >
          > Now when your list updates, it can just read the Item property of the
          > logger:
          >
          > '// Client Code
          > ListView.BeginU pdate
          > ListView.Items. Clear
          >
          > For I as Integer = 0 to Logger.EntryCou nt
          > ListView.Items. Add ( log )
          > Next
          >
          > ListView.EndUpd ate
          >
          >
          > What do you think?
          >
          > ~
          > Jeremy
          >[/color]


          Comment

          • Jeremy Cowles

            #6
            Re: Custom Event Logging / Shared Class

            > I could see where this could become cumbersome (especially if you had
            large[color=blue]
            > amounts of Event Data), so maybe even add a property about 'last event
            > added." or something...
            >
            > I don't know... thoughts?[/color]

            You could create an [Before|After]LogEntryAdded event, and make the
            EventArgs hold the data for the Entry that was added.

            Public Sub logger_LogEntry Added(o, e) handles x.x
            List.Add( e.Entry.ToStrin g( ) )
            End Sub

            ?

            ~
            Jeremy

            Comment

            Working...