Cant write to custom EventLog from Web Service - Permissions Issue?

Posted on 2012-04-05
Medium Priority
Last Modified: 2014-10-18
I have a web service that I want to write to a custom log.

I have created the log on the server and created the sources for it.

It feels like a permissions issue, but I cant get any info back from the server to tell me what I am doing wrong.  Can anyone point me in the right direction on this?  This works like a charm on my dev machine.

Here is the full class code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Diagnostics;
using My.Models;

namespace MyClass
    public class ServiceLogger
        public class LogObject
            public DateTime ExecuteTime { get; set; }
            public DateTime EndTime { get; set; }
            public String ServiceCall { get; set; }
            public String Status { get; set; }
            public TimeSpan Span
                    DateTime starttime = ExecuteTime;
                    DateTime endtime = EndTime;
                    return endtime.Subtract(starttime);
            public String StackTrace { get; set; }

        public static void WriteLog(LogObject l)
            string logMsg = CreateLogMessage(l);

            EventLog eLog = GetLog();

            EventLogEntryType eType = new EventLogEntryType();
            switch (l.Status)
                case "ERROR":
                    eType = EventLogEntryType.Error;
                case "SUCCESS":
                    eType = EventLogEntryType.SuccessAudit;
                    eType = EventLogEntryType.Information;

            eLog.WriteEntry(logMsg, eType, 1000, 0);

        public static EventLog GetLog()
            if (!EventLog.SourceExists("MySource"))
                EventLog.CreateEventSource("MyService", "MySource");

            EventLog eLog = new EventLog("MyService", ".", "MySource");
            return eLog;

        public static string CreateLogMessage(LogObject l)
            string logMsg = string.Empty;
            logMsg = "Status:  " + l.Status + "\r\n";
            logMsg += "Time Span:  " + l.Span.ToString() + "\r\n";
            logMsg += "Start Time: " + l.ExecuteTime.ToString() + "\r\n";
            logMsg += "End Time:  " + l.EndTime.ToString() + "\r\n";
            logMsg += "Service Called:  " + l.ServiceCall + "\r\n\n";

            logMsg += "Stack Trace:  " + l.StackTrace + "\r\n";

            return logMsg;

Open in new window

Question by:BlueMurder
LVL 11

Accepted Solution

Najam Uddin earned 2000 total points
ID: 37831035
If server if windows server 2003 or 2008 then you might have this issue as Eventlog need permission

Go through this article it will let you know if permission is that problem.
LVL 16

Expert Comment

by:Rose Babu
ID: 37836998

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question