private void WriteAuditEvent(AuditLevel auditLevel, X509Certificate2 certificate, WindowsSidIdentity wsid, Exception exception)
 {
     try
     {
         string clientIdentity = string.Empty;
         if (certificate != null)
         {
             clientIdentity = System.ServiceModel.Security.SecurityUtils.GetCertificateId(certificate);
         }
         else if (wsid != null)
         {
             clientIdentity = System.ServiceModel.Security.SecurityUtils.GetIdentityName(wsid);
         }
         if (auditLevel == AuditLevel.Success)
         {
             SecurityAuditHelper.WriteTransportAuthenticationSuccessEvent(base.AuditBehavior.AuditLogLocation, base.AuditBehavior.SuppressAuditFailure, null, this.Uri, clientIdentity);
         }
         else
         {
             SecurityAuditHelper.WriteTransportAuthenticationFailureEvent(base.AuditBehavior.AuditLogLocation, base.AuditBehavior.SuppressAuditFailure, null, this.Uri, clientIdentity, exception);
         }
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2) || (auditLevel == AuditLevel.Success))
         {
             throw;
         }
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error);
     }
 }
 private void WriteAuditEvent(StreamSecurityUpgradeAcceptor securityUpgradeAcceptor, AuditLevel auditLevel, Exception exception)
 {
     if (((this.transportSettings.AuditBehavior.MessageAuthenticationAuditLevel & auditLevel) == auditLevel) && (securityUpgradeAcceptor != null))
     {
         string clientIdentity = string.Empty;
         SecurityMessageProperty remoteSecurity = securityUpgradeAcceptor.GetRemoteSecurity();
         if (remoteSecurity != null)
         {
             clientIdentity = GetIdentityNameFromContext(remoteSecurity);
         }
         ServiceSecurityAuditBehavior auditBehavior = this.transportSettings.AuditBehavior;
         if (auditLevel == AuditLevel.Success)
         {
             SecurityAuditHelper.WriteTransportAuthenticationSuccessEvent(auditBehavior.AuditLogLocation, auditBehavior.SuppressAuditFailure, null, this.Via, clientIdentity);
         }
         else
         {
             SecurityAuditHelper.WriteTransportAuthenticationFailureEvent(auditBehavior.AuditLogLocation, auditBehavior.SuppressAuditFailure, null, this.Via, clientIdentity, exception);
         }
     }
 }
 protected void WriteAuditEvent(AuditLevel auditLevel, string primaryIdentity, Exception exception)
 {
     try
     {
         if (auditLevel == AuditLevel.Success)
         {
             SecurityAuditHelper.WriteTransportAuthenticationSuccessEvent(base.AuditBehavior.AuditLogLocation, base.AuditBehavior.SuppressAuditFailure, null, this.Uri, primaryIdentity);
         }
         else
         {
             SecurityAuditHelper.WriteTransportAuthenticationFailureEvent(base.AuditBehavior.AuditLogLocation, base.AuditBehavior.SuppressAuditFailure, null, this.Uri, primaryIdentity, exception);
         }
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2) || (auditLevel == AuditLevel.Success))
         {
             throw;
         }
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error);
     }
 }