473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Logging to a customer Eventlog From a c#windows service

Hi,
does any have any sample code of the above?

i have tried the example from the help but am unable to get my windows
service to create a new logfile and start logging to it.
I am able to create one however if my application is a windows form
application.
Thanks in advance

TimB


public UserService2()
{
this.AutoLog = false;
// create an event source, specifying the name of a log that
// does not currently exist to create a new, custom log
if (!System.Diagnostics.EventLog.SourceExists("MySour ce"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource","MyLog");
}
// configure the event log instance to use this source name
eventLog1.Source = "MySource";
}

protected override void OnStart(string[] args)
{
// write an entry to the log
eventLog1.WriteEntry("In OnStart.");
}
Nov 15 '05 #1
1 2258

Tim,
Certain tasks in .NET need some security privilege to perform them.
You should have a window app or console app that creates the EventLogs and
the EventSources your app uses. This should be executed by some
administrator (usualy the Operations department). Then your windows service
would be able to log events successfully.
The same problem you would have if your app was an aspx.
This is all by design. It is part of the security provision. Admins (highly
trusted accounts) should first install and create whatever will later be
used by Apps (less trusted accounts).

--
Thanks.
Paulo

DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights. Use of any included code samples are subject to the terms
specified at http://www.microsoft.com/info/cpyright.htm"
"timb" <ti**@nospam.com> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
Hi,
does any have any sample code of the above?

i have tried the example from the help but am unable to get my windows
service to create a new logfile and start logging to it.
I am able to create one however if my application is a windows form
application.
Thanks in advance

TimB


public UserService2()
{
this.AutoLog = false;
// create an event source, specifying the name of a log that
// does not currently exist to create a new, custom log
if (!System.Diagnostics.EventLog.SourceExists("MySour ce"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource","MyLog");
}
// configure the event log instance to use this source name
eventLog1.Source = "MySource";
}

protected override void OnStart(string[] args)
{
// write an entry to the log
eventLog1.WriteEntry("In OnStart.");
}

Nov 15 '05 #2

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

Similar topics

3
by: Jeff Shannon | last post by:
I'm having some difficulty getting my logging configuration set correctly. I'm using a config file (copied at end of post), with the intent of setting several loggers which write to a combination...
1
by: j vickroy | last post by:
My system: MSW XP professional Python 2.3.3 logging package: 0.4.9.2 My problem: The log_test3.py script, provided with the logging package distribution, generates an unexpected message: No...
5
by: timb | last post by:
Hi, am creating a windows service using c# and would like it to create a new eventlog logtype and add it to the eventlog viewer so that i can log all messages relating to this application to this...
6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
1
by: McKool | last post by:
Hello. I'm making a Windows service with C#. This service connect a comm Port when start and disconnect it when stop. I use an EventLog class to write information about this service, by...
4
by: Jeff | last post by:
I have a program that watches folders for any modifications and then writees to the Event Log. Problem is , is that it writes it four (4) times. I will post the code below and hopefully somone can...
0
by: TonyJ | last post by:
Hello! I want to write to my own custom log for my service and not to the generell programlogg. My service is called TestService and my log is called TestLog. Below is the relevant code that...
5
by: Daniel S | last post by:
Hi, I'm new here. I'm using the Logging Application Block with Enterprise Library 3.1. My program works correctly on my XP developer station, but on the 2003 Server, no new entries appear in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.