Exemplo n.º 1
0
        public static void LogResponse(GlsLoggerContext context, GLSLogger.StatusCode statusCode, ResponseBase response, GlsRawResponse rawResponse)
        {
            int    num = Environment.TickCount - context.TickStart;
            string resultCode;

            switch (statusCode)
            {
            case GLSLogger.StatusCode.Found:
                resultCode = "Found";
                break;

            case GLSLogger.StatusCode.NotFound:
                resultCode = "NotFound";
                break;

            case GLSLogger.StatusCode.WriteSuccess:
                resultCode = "Success";
                break;

            default:
                throw new ArgumentException("statusCode");
            }
            GLSLogger.BeginAppend(context.MethodName, context.ParameterValue, context.ResolveEndpointToIpAddress(false), resultCode, rawResponse, (long)num, string.Empty, response.TransactionID, context.ConnectionId, response.Diagnostics);
            ADProviderPerf.UpdateGlsCallLatency(context.MethodName, context.IsRead, num, true);
        }
Exemplo n.º 2
0
        private static void Initialize(ExDateTime serviceStartTime, string logFilePath, TimeSpan maxRetentionPeriond, ByteQuantifiedSize directorySizeQuota, ByteQuantifiedSize perFileSizeQuota, bool applyHourPrecision)
        {
            int registryInt;

            using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ADAccess\\Parameters"))
            {
                GLSLogger.Enabled = GLSLogger.GetRegistryBool(registryKey, "ProtocolLoggingEnabled", true);
                registryInt       = GLSLogger.GetRegistryInt(registryKey, "LogBufferSize", 65536);
            }
            if (GLSLogger.registryWatcher == null)
            {
                GLSLogger.registryWatcher = new RegistryWatcher("SYSTEM\\CurrentControlSet\\Services\\MSExchange ADAccess\\Parameters", false);
            }
            if (GLSLogger.timer == null)
            {
                GLSLogger.timer = new Timer(new TimerCallback(GLSLogger.UpdateConfigIfChanged), null, 0, 300000);
            }
            if (GLSLogger.Enabled)
            {
                GLSLogger.log = new Log(GLSLogger.logFilePrefix, new LogHeaderFormatter(GLSLogger.schema, LogHeaderCsvOption.CsvCompatible), "GLSLogs");
                GLSLogger.log.Configure(logFilePath, maxRetentionPeriond, (long)directorySizeQuota.ToBytes(), (long)perFileSizeQuota.ToBytes(), applyHourPrecision, registryInt, GLSLogger.defaultFlushInterval);
                AppDomain.CurrentDomain.ProcessExit += GLSLogger.CurrentDomain_ProcessExit;
            }
            GLSLogger.Initialized = true;
        }
Exemplo n.º 3
0
        public static T LoggingWrapper <T>(LocatorServiceClientAdapter glsClientAdapter, string parameter, string connectionId, Func <T> method) where T : ResponseBase
        {
            string ipAddress     = glsClientAdapter.ResolveEndpointToIpAddress(false);
            string diagnostics   = string.Empty;
            string transactionId = string.Empty;
            string text          = string.Empty;
            int    tickCount     = Environment.TickCount;
            T      result;

            try
            {
                GLSLogger.FaultInjectionTrace();
                result        = method();
                diagnostics   = result.Diagnostics;
                transactionId = result.TransactionID;
            }
            catch (Exception ex)
            {
                text      = ex.Message;
                ipAddress = glsClientAdapter.ResolveEndpointToIpAddress(true);
                throw;
            }
            finally
            {
                int    num        = Environment.TickCount - tickCount;
                string resultCode = string.IsNullOrEmpty(text) ? "Success" : "Exception";
                GLSLogger.BeginAppend(method.Method.Name, parameter, ipAddress, resultCode, null, (long)num, text, transactionId, connectionId, diagnostics);
                bool   isRead;
                string apiName = GLSLogger.ApiNameFromReturnType <T>(out isRead);
                ADProviderPerf.UpdateGlsCallLatency(apiName, isRead, num, string.IsNullOrEmpty(text));
            }
            return(result);
        }
Exemplo n.º 4
0
        public static void LogException(GlsLoggerContext context, Exception ex)
        {
            int        num        = Environment.TickCount - context.TickStart;
            StackTrace stackTrace = new StackTrace(false);

            GLSLogger.BeginAppend(context.MethodName, context.ParameterValue, context.ResolveEndpointToIpAddress(true), "Exception", null, (long)num, ex.Message + stackTrace.ToString(), context.RequestTrackingGuid.ToString(), context.ConnectionId, string.Empty);
            ADProviderPerf.UpdateGlsCallLatency(context.MethodName, context.IsRead, num, false);
        }
Exemplo n.º 5
0
 private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
 {
     lock (GLSLogger.logLock)
     {
         GLSLogger.Enabled     = false;
         GLSLogger.Initialized = false;
         GLSLogger.Shutdown();
     }
 }
Exemplo n.º 6
0
 private static void AppendInternal(string operation, string parameter, string ipAddress, string resultCode, GlsRawResponse rawResponse, long processingTime, string failure, string transactionid, string connectionid, string diagnostics, Guid activityId)
 {
     if (rawResponse == null)
     {
         rawResponse = new GlsRawResponse();
     }
     if (!GLSLogger.Initialized)
     {
         lock (GLSLogger.logLock)
         {
             if (!GLSLogger.Initialized)
             {
                 GLSLogger.Initialize(ExDateTime.UtcNow, Path.Combine(GLSLogger.GetExchangeInstallPath(), "Logging\\GLS\\"), GLSLogger.defaultMaxRetentionPeriod, GLSLogger.defaultDirectorySizeQuota, GLSLogger.defaultPerFileSizeQuota, true);
             }
         }
     }
     if (GLSLogger.Enabled)
     {
         LogRowFormatter logRowFormatter = new LogRowFormatter(GLSLogger.schema);
         logRowFormatter[1]  = GLSLogger.GetNextSequenceNumber();
         logRowFormatter[2]  = Globals.ProcessName;
         logRowFormatter[3]  = Globals.ProcessId;
         logRowFormatter[4]  = Globals.ProcessAppName;
         logRowFormatter[5]  = Environment.CurrentManagedThreadId;
         logRowFormatter[6]  = operation;
         logRowFormatter[7]  = parameter;
         logRowFormatter[9]  = processingTime;
         logRowFormatter[8]  = resultCode;
         logRowFormatter[10] = ipAddress;
         logRowFormatter[11] = rawResponse.ResourceForest;
         logRowFormatter[12] = rawResponse.AccountForest;
         logRowFormatter[13] = rawResponse.TenantContainerCN;
         logRowFormatter[14] = rawResponse.TenantId;
         logRowFormatter[15] = rawResponse.SmtpNextHopDomain;
         logRowFormatter[16] = rawResponse.TenantFlags;
         logRowFormatter[17] = rawResponse.DomainName;
         logRowFormatter[18] = rawResponse.DomainInUse;
         logRowFormatter[19] = rawResponse.DomainFlags;
         logRowFormatter[20] = failure;
         logRowFormatter[21] = transactionid;
         logRowFormatter[22] = connectionid;
         logRowFormatter[23] = diagnostics;
         logRowFormatter[24] = activityId;
         GLSLogger.log.Append(logRowFormatter, 0);
     }
 }
Exemplo n.º 7
0
 private static void UpdateConfigIfChanged(object state)
 {
     if (GLSLogger.registryWatcher.IsChanged())
     {
         using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ADAccess\\Parameters"))
         {
             bool registryBool = GLSLogger.GetRegistryBool(registryKey, "ProtocolLoggingEnabled", true);
             if (registryBool != GLSLogger.Enabled)
             {
                 lock (GLSLogger.logLock)
                 {
                     GLSLogger.Initialized = false;
                     GLSLogger.Enabled     = registryBool;
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
        internal static void Append(string operation, string parameter, string ipAddress, string resultCode, GlsRawResponse rawResponse, long processingTime, string failure, string transactionid, string connectionid, string diagnostics)
        {
            Guid activityId = Guid.Empty;

            try
            {
                IActivityScope currentActivityScope = ActivityContext.GetCurrentActivityScope();
                if (currentActivityScope != null && currentActivityScope.Status == ActivityContextStatus.ActivityStarted)
                {
                    activityId = currentActivityScope.ActivityId;
                }
            }
            catch (Exception ex)
            {
                diagnostics += ex.ToString();
            }
            GLSLogger.AppendInternal(operation, parameter, ipAddress, resultCode, rawResponse, processingTime, failure, transactionid, connectionid, diagnostics, activityId);
        }