473,811 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 20 '05 #1
5 3014
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:
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


Nov 20 '05 #2
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" <be***@mvps.org > wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
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:
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

Nov 20 '05 #3
> 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?


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

Nov 20 '05 #4
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:uu******** *******@twister .tampabay.rr.co m...
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?
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

Nov 20 '05 #5
> 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?


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

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1954
by: Andreas Jung | last post by:
I am trying to write a custom logger with a custom handler: class MyHandler(StreamHandler): pass class Logger: def __init__(self): self._l = logging.getLogger('someident') self._l.addHandler(MyHandler('/path/to/logfile'))
9
5764
by: Marcin Kalicinski | last post by:
Hi, I have a set of C-like functions for file access (like fopen, fwrite, fread, fseek etc.). But I want to access the files using C++ stream, not these functions. What I probably need to do is to create custom streambuf class (am I right?). Is there any free source code or tutorial available on how to do that? I have googled for it, but I only found partial and untested solutions. Worse, the solutions were pretty complicated,...
1
2197
by: AMDRIT | last post by:
'System.Runtime.InteropServices.SEHException' occurred in system.windows.forms.dll is generated when I use "My Custom Dialog". Any ideas what I could be doing wrong? Basically, I wanted to create a dialog like Messagebox. I created a class with a public shared function that returns a dialogresult. I then created a form with an event and two buttons. TIA Public Class policyStatusChange
1
2643
by: Beren | last post by:
Hello With trial and error I'm attempting to create an extended identity to store some more data than just the Name, for example a Subscription and a LastSearchPerformed property... Is this a good idea ? I'm coming from ASP and Session variables, but I explicitly wanted to avoid that for .NET. The problem I'm facing is that I don't find a good way to bring my source
1
4145
by: David Herbst | last post by:
Enterprise Library Jan 2006 with Visual Studio 2005 on Windows 2000 Server sp4. My custom exception formatter fails with a "Unable to handle exception: 'LoggingExceptionHandler'." exception. When I attached the debugger to the process and stepped into the code it executed without error. In both cases I was running a Debug build, the only difference in the case that works is that I attached the debugger to the same exact binaries....
2
2534
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in Development Environment; may be a few example(s) will help me understand.
0
5016
by: Eniac | last post by:
Hello, I've started using Enterprise Library 2.0 recently and I've encountered a problem that seems to be ... well... undocumented :) Basically, when I set a Trace Listener (formatted event log to be precise), if i specify the name of a custom event log, the listener won't log in it. I've checked in the registry, the log is there. In the event viewer, I
0
1656
by: =?Utf-8?B?U2hyaWthbnQgTW9yZQ==?= | last post by:
Using enterprise library's 3.1 Logging Application Block , how can i get the custom source name in the windows event log.When ever i am logging an error in windows event log , it gives the source name as Enterprise Library Logging.I want my custom source name instead of Enterprise Library Logging.Also how can i get the username and category also, through Logging Application Block.
3
6430
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the logging.config.fileConfig() function. Let say my logging class is called "MyLogHandler" and it's in a module called "mylogmodule", I want to be able to make an entry something like this in my logging config file:
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.