public static void WriteTrace(uint tag, TraceSeverity level, Guid correlationGuid, string exeName, string productName, string categoryName, string message)
        {
            const ushort sizeOfWCHAR = 2;
            NativeMethods.ULSTrace ulsTrace = new NativeMethods.ULSTrace();

            // Pretty standard code needed to make things work
            ulsTrace.Header.Size = (ushort)Marshal.SizeOf(typeof(NativeMethods.ULSTrace));
            ulsTrace.Header.Flags = NativeMethods.WNODE_FLAG_TRACED_GUID;
            ulsTrace.ULSHeader.dwVersion = NativeMethods.TRACE_VERSION_CURRENT;
            ulsTrace.ULSHeader.dwFlags = NativeMethods.TraceFlags.TRACE_FLAG_ID_AS_ASCII;
            ulsTrace.ULSHeader.Size = (ushort)Marshal.SizeOf(typeof(NativeMethods.ULSTraceHeader));

            // Variables communicated to SPTrace
            ulsTrace.ULSHeader.Id = tag;
            ulsTrace.Header.Class.Level = (byte)level;
            ulsTrace.ULSHeader.wzExeName = exeName;
            ulsTrace.ULSHeader.wzProduct = productName;
            ulsTrace.ULSHeader.wzCategory = categoryName;
            ulsTrace.ULSHeader.wzMessage = message;
            ulsTrace.ULSHeader.correlationID = correlationGuid;

            // Pptionally, to improve performance by reducing the amount of data copied around,
            // the Size parameters can be reduced by the amount of unused buffer in the Message
            if (message.Length < 800)
            {
                ushort unusedBuffer = (ushort)((800 - (message.Length + 1)) * sizeOfWCHAR);
                ulsTrace.Header.Size -= unusedBuffer;
                ulsTrace.ULSHeader.Size -= unusedBuffer;
            }

            if (hTraceLog != 0)
                NativeMethods.TraceEvent(hTraceLog, ref ulsTrace);
        }
Beispiel #2
0
        internal static void WriteTrace(uint tag, TraceSeverity level, Guid correlationGuid, string exeName,
                                        string productName, string categoryName, string message)
        {
            const ushort sizeOfWCHAR = 2;

            var ulsTrace = new NativeMethods.ULSTrace();


            // Pretty standard code needed to make things work

            ulsTrace.Header.Size = (ushort)Marshal.SizeOf(typeof(NativeMethods.ULSTrace));

            ulsTrace.Header.Flags = NativeMethods.WNODE_FLAG_TRACED_GUID;

            ulsTrace.ULSHeader.dwVersion = NativeMethods.TRACE_VERSION_CURRENT;

            ulsTrace.ULSHeader.dwFlags = TraceFlags.IdAsASCII;

            ulsTrace.ULSHeader.Size = (ushort)Marshal.SizeOf(typeof(NativeMethods.ULSTraceHeader));


            // Variables communicated to SPTrace

            ulsTrace.ULSHeader.Id = tag;

            ulsTrace.Header.Class.Level = (byte)level;

            ulsTrace.ULSHeader.wzExeName = exeName;

            ulsTrace.ULSHeader.wzProduct = productName;

            ulsTrace.ULSHeader.wzCategory = categoryName;

            ulsTrace.ULSHeader.wzMessage = message;

            ulsTrace.ULSHeader.correlationID = correlationGuid;


            // Pptionally, to improve performance by reducing the amount of data copied around,

            // the Size parameters can be reduced by the amount of unused buffer in the Message

            if (message.Length < 800)
            {
                var unusedBuffer = (ushort)((800 - (message.Length + 1)) * sizeOfWCHAR);

                ulsTrace.Header.Size -= unusedBuffer;

                ulsTrace.ULSHeader.Size -= unusedBuffer;
            }


            if (_hTraceLog != 0)
            {
                NativeMethods.TraceEvent(_hTraceLog, ref ulsTrace);
            }
        }