EventLog Security Privileges

  • Thread starter Thread starter Colin Mackay
  • Start date Start date
C

Colin Mackay

How do I write to the event log in a Windows Service that does not
have administrator privileges? The target platforms are Windows Server
2003 and Windows XP Professional.
 
You should have access to write to the EventLog providing that the Category in the EventLog already exist

You should create an installer class for you Windows Service to check to see if the Category already exists, if it doesn't then create it

System.Diagnostics.EventLog.CreateEventSource("MyWebService", "Application");
 
Hey

Your call to PrintMe in the constructor for SerializeMe does not work because your object is created inside out so the NameValueCollection has not yet been fully constructed when you call PrintMe

I have tried to find a solution for this. I tried letting SerializeMe implement IDeserializationCallback and the call PrintMe in the implementation of OnDeserialization. This does not seem to work. However, NameValueCollection also implements IDeserializationCallback so I tried creating a new class inheriting NameValueCollection and then overriding NameValueCollection.OnDeserialization. This ALMOST works since I am able to get the correct item count and I am also able to extract the keys. However, for some strange reason, if I try to extract the values of the NameValueCollection, I get an exception

Instead of inheriting from NameValueCollection I then tried inheriting from Hashtable. In the override of OnDeserialization I can now extract and print the values of the hashtable. So Hashtable and NameValueCollection do not behave the same way

Here is my code

[Serializable
public class NameValueCollectionEx : System.Collections.Hashtabl

public NameValueCollectionEx(
: base(



protected NameValueCollectionEx(SerializationInfo info, StreamingContext context)
: base(info, context



public override void OnDeserialization(object sender

base.OnDeserialization (sender)

Console.WriteLine("Items: " + this.Count)
foreach (string key in this.Keys)

Console.WriteLine("Key: " + key + "->" + this[key].ToString())




[Serializable
public class SerializeMe : ISerializable, IDeserializationCallbac

private NameValueCollectionEx values

public SerializeMe()

values = new NameValueCollectionEx()
values.Add("string1", "hi")
values.Add("string2", "there")


protected SerializeMe(SerializationInfo info, StreamingContext context)

values = (NameValueCollectionEx) info.GetValue("values", typeof(NameValueCollectionEx))


// The rest of your code goes here..


Regards, Jakob.
 
Back
Top