|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Use a static form of the EventLog class?Programmer's Guide for the .NET Framework - How to: Log Information About Services, the following statement is made: By default, all Windows Service projects have the ability to interact with the Application event log and write information and exceptions to it. You use the AutoLog property to indicate whether you want this functionality in your application. By default, logging is turned on for any service you create with the Windows Service project template. You can use a static form of the EventLog class to write service information to a log without having to create an instance of an EventLog component or manually register a source. So, in my code, I use the following: EventLog.WriteEntry("Socket connected!") But the IDE indicates there is a problem, and this is the error message: Error 1 Reference to a non-shared member requires an object reference. EventLog.Write Entry is Shared, but it requires an instance of an EventInstance, and the methods require using a resource file. This app is for use only in our company and I really don't want to go to the trouble of creating a resource file, etc. (trying to keep it simple ;-). Can anyone point me to a sample of a Windows Service that uses the default AutoLog showing how to do the logging? Thanks!
Show quote
Hide quote
"Ron Hinds" <nospam@dontspamme.com> wrote in message Never mind. I figured it out. For anyone else who might be in need of the news:unaYLDq1KHA.224@TK2MSFTNGP06.phx.gbl... > I'm developing a Windows Service in VB.Net. In the Visual Studio > Programmer's Guide for the .NET Framework - How to: Log Information About > Services, the following statement is made: > > By default, all Windows Service projects have the ability to interact with > the Application event log and write information and exceptions to it. You > use the AutoLog property to indicate whether you want this functionality > in your application. By default, logging is turned on for any service you > create with the Windows Service project template. You can use a static > form of the EventLog class to write service information to a log without > having to create an instance of an EventLog component or manually register > a source. > > So, in my code, I use the following: > > EventLog.WriteEntry("Socket connected!") > > But the IDE indicates there is a problem, and this is the error message: > > Error 1 Reference to a non-shared member requires an object reference. > > EventLog.Write Entry is Shared, but it requires an instance of an > EventInstance, and the methods require using a resource file. This app is > for use only in our company and I really don't want to go to the trouble > of creating a resource file, etc. (trying to keep it simple ;-). > > Can anyone point me to a sample of a Windows Service that uses the default > AutoLog showing how to do the logging? Thanks! answer - it is only the first overload of WriteEntry that isn't Shared - so this code works: EventLog.WriteEntry("MyService", "Socket connected!") On 07/04/2010 23:59, Ron Hinds wrote:
Show quoteHide quote > "Ron Hinds"<nospam@dontspamme.com> wrote in message Permit me to say ...> news:unaYLDq1KHA.224@TK2MSFTNGP06.phx.gbl... >> So, in my code, I use the following: >> >> EventLog.WriteEntry("Socket connected!") >> >> But the IDE indicates there is a problem, and this is the error message: >> >> Error 1 Reference to a non-shared member requires an object reference. >> >> EventLog.Write Entry is Shared, but it requires an instance of an >> EventInstance, and the methods require using a resource file. This app is >> for use only in our company and I really don't want to go to the trouble >> of creating a resource file, etc. (trying to keep it simple ;-). > Never mind. I figured it out. For anyone else who might be in need of the > answer - it is only the first overload of WriteEntry that isn't Shared - so > this code works: > > EventLog.WriteEntry("MyService", "Socket connected!") "Well done" for figuring it out and, perhaps more importantly around here, thank you for sharing the solution! It is /so/ annoying when you "Google" a problem (is that a verb yet) only to find some banal "I fixed it" note (and nothing else) at the end of the thread. Regards, Phill W.
How to tell if folder item is file or folder?
null reference exception could result at runtime How to get the list of all SQL Server foreign keys in a database by using Microsoft.SqlServer.Manage Problem passing exception from AppDomain want to convert string into byte array hw i can do it datagridview Combobox column Adding/copying Worksheet to Excel Programmatically add Sub Menus to a ContextMenuStrip HTML report in vb.net master - detail architecture for dataTable. |
|||||||||||||||||||||||