RE: I implemanted Custom Event Schema, Custom Event Sink and I have a problem
From: Mike Hayton [MS] (mikehayt__at_online.microsoft.com)
Date: 07/28/04
- Next message: Mike Hayton [MS]: "RE: Some general questions on EIF wrt EventViewer"
- Previous message: Mike Hayton [MS]: "Re: EIF Trace Log with distributed application"
- In reply to: ÀÌÀÏ·Ä: "I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Next in thread: ÀÌÀÏ·Ä: "Re: I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Reply: ÀÌÀÏ·Ä: "Re: I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Jul 2004 01:51:34 GMT
Hi there
Are you still having problems with this?
I would assume that the problem is occuring in the custom event sink.
I would initially run perfmon and have a look at the InternalErrors perf
counter under the EventSources: Software Elements & EventSources: Request
categories. This way you'll be able to see if the custom event sink is
throwing an exception in its Write() method.
Does closing the Mutex handle delete the mutex - In the case of multiple
instances of custom event sink, when one is Disposed is it causing problems
for the others?
Cheers
Mike
--------------------
|
| ## Event Schema
| namespace MiMiC.EnterpriseInstrumentation.Schema
| {
| /// <summary>
| /// Summary description for MiMiCEvent.
| /// </summary>
| public class MiMiCEvent : BaseEvent
| {
| public MiMiCEvent() {}
|
| public DateTime m_timeLOG;
| public string m_strEventSourceName;
| public string m_strScheduleType;
| public long m_lScheduleID;
| public long m_lScenarioID;
| public long m_lTargetID;
| public string m_strLOG;
|
| public override bool PrepareForSerialization(EventSource eventSource,
| RequestContext requestContext)
| {
| if (!base.PrepareForSerialization(eventSource, requestContext)) return
| false;
|
| m_strEventSourceName = eventSource.Name;
| m_timeLOG = DateTime.Now;
|
| return true;
| }
|
| public static void Raise(EventSource eventSource, string strLOG)
| {
| if (eventSource == null) throw new
ArgumentNullException("eventSource");
|
| MiMiCEvent e = new MiMiCEvent();
|
| e.m_strScheduleType = "NONE";
| e.m_lScheduleID = -1;
| e.m_lScenarioID = -1;
| e.m_lTargetID = -1;
| e.m_strLOG = strLOG;
|
| eventSource.Raise(e);
| }
|
| public static void Raise(EventSource eventSource, string
strScheduleType,
| long lScheduleID, long lScenarioID, long lTargetID, string strLOG)
| {
| if (eventSource == null) throw new
ArgumentNullException("eventSource");
|
| MiMiCEvent e = new MiMiCEvent();
|
| strScheduleType = strScheduleType.ToUpper();
|
| if(strScheduleType.IndexOf("EMULATOR") != -1) strScheduleType = "QT";
| if(strScheduleType.IndexOf("AGENT") != -1) strScheduleType = "LT";
|
| e.m_strScheduleType = strScheduleType;
| e.m_lScheduleID = lScheduleID;
| e.m_lScenarioID = lScenarioID;
| e.m_lTargetID = lTargetID;
| e.m_strLOG = strLOG;
|
| eventSource.Raise(e);
| }
| }
| }
|
| ## Event Sink
| namespace MiMiC.EnterpriseInstrumentation.EventSinks
| {
| public class MiMiCEventSink : EventSink, IEventContainerSink
| {
| [StructLayoutAttribute(LayoutKind.Sequential)]
| public struct SECURITY_ATTRIBUTES
| {
| public uint dwSize;
| public int lpSecurityDescriptor;
| public bool bInheritHandle;
| }
|
| [StructLayoutAttribute(LayoutKind.Sequential)]
| public struct SECURITY_DESCRIPTOR
| {
| public byte revision;
| public byte size;
| public short control;
| public IntPtr owner;
| public IntPtr Group;
| public IntPtr Sacl;
| public IntPtr Dacl;
| }
|
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern UInt32 CreateMutex(ref SECURITY_ATTRIBUTES
| SecurityAttributes, bool InitialOwner, string MutexName);
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern UInt32 OpenMutex(UInt32 dwDesiredAccess, bool
| bInheritHandle, string MutexName);
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern bool ReleaseMutex(UInt32 hMutex);
| [DllImport("Advapi32.dll", SetLastError=true)]
| private static extern bool
| ConvertStringSecurityDescriptorToSecurityDescriptor(string
| StringSecurityDescriptor, UInt32 StringSDRevision, ref int
| SecurityDescriptor, ref int SecurityDescriptorSize);
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern UInt32 LocalFree(UInt32 hMem);
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern UInt32 WaitForSingleObject(UInt32 hHandle, UInt32
| dwMilliseconds);
| [DllImport("kernel32.dll", SetLastError=true)]
| private static extern bool CloseHandle(UInt32 hHandle);
|
| private UInt32 CreateMutex_Wrap(bool initiallyOwned, string name)
| {
| UInt32 hResult = 0;
|
| UInt32 SYNCHRONIZE = 0x00100000;
| UInt32 SDDL_REVISION_1 = 1;
| // UInt32 ERROR_ALREADY_EXISTS = 183;
|
| // It's faster to first try OpenMutex
| hResult = OpenMutex(SYNCHRONIZE, true, name);
|
| if(hResult == 0)
| {
| SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
| sa.dwSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(sa);
| sa.bInheritHandle = true;
| sa.lpSecurityDescriptor = 0;
|
| int securityDescriptorSize = 0; // dummy
| bool result = ConvertStringSecurityDescriptorToSecurityDescriptor(
| "D:(A;NP;0x001f0001;;;WD)", // Grant MUTEX_ALL_ACCESS
| SDDL_REVISION_1,
| ref sa.lpSecurityDescriptor,
| ref securityDescriptorSize);
|
| if (result == false) throw new Exception("Failure while creating
| security descriptor for new mutex");
|
| hResult = CreateMutex(ref sa, initiallyOwned, name);
| // createdNew = (Marshal.GetLastWin32Error() != ERROR_ALREADY_EXISTS);
|
| LocalFree((UInt32)sa.lpSecurityDescriptor);
| }
|
| return hResult;
| }
|
| private string m_strLogFilePath;
| private UInt32 m_hMutex;
|
| public MiMiCEventSink(IDictionary parameters, EventSource eventSource) :
| base(parameters, eventSource)
| {
| if (parameters == null)
| throw new ArgumentNullException("parameters");
|
| m_strLogFilePath = parameters["LogFilePath"] as string;
| m_hMutex = CreateMutex_Wrap(false, "MiMiCEventSink");
| }
|
| public override void Write(object eventToRaise)
| {
| throw new NotSupportedException();
| }
|
| [MethodImpl(MethodImplOptions.Synchronized)]
| public unsafe void Write(EventContainer eventContainer)
| {
| if (eventContainer == null)
| throw new ArgumentNullException("eventcontainer");
|
| EventEntrySerializer serializer = new EventEntrySerializer();
| eventContainer.Evaluate(serializer);
| EventEntry evententry = serializer.GetEventEntry();
|
| StreamWriter streamWriter;
|
| string strTemp;
| string strFilePath;
| DateTime timeNow = DateTime.Now;
| strFilePath = m_strLogFilePath + "_" +
| String.Format("{0:0000}_{1:00}_{2:00}", timeNow.Year, timeNow.Month,
| timeNow.Day);
| strFilePath += ".log";
|
| WaitForSingleObject(m_hMutex, UInt32.MaxValue); // UInt32.MaxValue ==
| INFINITE
|
| try
| {
| streamWriter = File.AppendText(strFilePath);
| streamWriter.AutoFlush = true;
|
| if(evententry.Type.ToString() ==
| "MiMiC.EnterpriseInstrumentation.Schema.MiMiCEvent")
| {
| foreach(DictionaryEntry deOne in evententry)
| {
| if(deOne.Value.GetType().Name == "DateTime")
| {
| DateTime dtOne = (DateTime)deOne.Value;
|
| strTemp = String.Format("{0:0000}-{1:00}-{2:00}
| {3:00}:{4:00}:{5:00}",
| dtOne.Year, dtOne.Month, dtOne.Day,
| dtOne.Hour, dtOne.Minute, dtOne.Second);
| }
| else
| {
| strTemp = deOne.Value.ToString();
| }
|
| streamWriter.Write( "{0}\t", strTemp );
| }
|
| streamWriter.Write(streamWriter.NewLine);
| }
|
| streamWriter.Flush();
| streamWriter.Close();
| }
| catch(Exception err)
| {
| throw err;
| }
| finally
| {
| ReleaseMutex(m_hMutex);
| }
| }
|
| // Dispose of resources.
| protected override void Dispose(bool disposing)
| {
| if (disposing)
| {
| // Free state-managed objects.
| CloseHandle(m_hMutex);
| }
| base.Dispose(disposing);
| }
| }
| }
|
|
| ######################################################
| this work is fine,
| but sometime lose custom event,
| somebody help me
|
|
|
-- This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
- Next message: Mike Hayton [MS]: "RE: Some general questions on EIF wrt EventViewer"
- Previous message: Mike Hayton [MS]: "Re: EIF Trace Log with distributed application"
- In reply to: ÀÌÀÏ·Ä: "I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Next in thread: ÀÌÀÏ·Ä: "Re: I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Reply: ÀÌÀÏ·Ä: "Re: I implemanted Custom Event Schema, Custom Event Sink and I have a problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|