Solved

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

Posted on 2012-04-05
4
232 Views
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
            {
                get
                {
                    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;
                    break;
                case "SUCCESS":
                    eType = EventLogEntryType.SuccessAudit;
                    break;
                default:
                    eType = EventLogEntryType.Information;
                    break;
            }

            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

0
Comment
Question by:BlueMurder
4 Comments
 
LVL 10

Accepted Solution

by:
Najam Uddin earned 500 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.
http://support.microsoft.com/default.aspx?kbid=323076
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37836998
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AJAX call to web service 4 89
jax-ws end to end example 2 74
Paint/Redraw window while dragging 16 75
Limiting access to WCF service using Windows authentication 5 73
These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now