protected override void ProcessRecord()
        {
            LogMetric logMetric = new LogMetric()
            {
                Name        = MetricName,
                Description = Description
            };

            logMetric.Filter = ConstructLogFilterString(
                logName: PrefixProjectToLogName(LogName, Project),
                logSeverity: Severity,
                selectedType: SelectedResourceType,
                before: Before,
                after: After,
                otherFilter: Filter);

            try
            {
                LoggingBaseServiceRequest <LogMetric> request = GetRequest(logMetric);
                LogMetric result = request.Execute();
                WriteObject(result);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Conflict)
            {
                WriteResourceExistsError(
                    exceptionMessage: $"Cannot create '{MetricName}' in project '{Project}' because it already exists.",
                    errorId: "MetricAlreadyExists",
                    targetObject: MetricName);
            }
        }
        protected override void ProcessRecord()
        {
            LogSink logSink = new LogSink()
            {
                Name = SinkName
            };

            string permissionRequest = "";

            switch (ParameterSetName)
            {
            case ParameterSetNames.GcsBucketDestination:
                logSink.Destination = $"storage.googleapis.com/{GcsBucketDestination}";
                permissionRequest   = $"'Owner' permission to the bucket '{GcsBucketDestination}'.";
                break;

            case ParameterSetNames.BigQueryDataSetDestination:
                logSink.Destination = $"bigquery.googleapis.com/projects/{Project}/datasets/{BigQueryDataSetDestination}";
                permissionRequest   = $"'Can edit' permission to the dataset '{BigQueryDataSetDestination}'.";
                break;

            case ParameterSetNames.PubSubTopicDestination:
                logSink.Destination = $"pubsub.googleapis.com/projects/{Project}/topics/{PubSubTopicDestination}";
                permissionRequest   = $"'Editor' permission in the project '{Project}'.";
                break;
            }

            string logName = PrefixProjectToLogName(LogName, Project);

            // The sink already has before and after filter so we do not have to supply it.
            logSink.Filter = ConstructLogFilterString(
                logName: logName,
                logSeverity: Severity,
                selectedType: SelectedResourceType,
                before: null,
                after: null,
                otherFilter: Filter);

            if (Before.HasValue)
            {
                logSink.EndTime = XmlConvert.ToString(Before.Value, XmlDateTimeSerializationMode.Local);
            }

            if (After.HasValue)
            {
                logSink.StartTime = XmlConvert.ToString(After.Value, XmlDateTimeSerializationMode.Local);
            }

            LoggingBaseServiceRequest <LogSink> request = GetRequest(logSink);

            try
            {
                LogSink createdSink = request.Execute();
                WriteObject(createdSink);
                // We want to let the user knows that they have to grant appropriate permission to the writer identity
                // so that the logs can be exported (otherwise, the export will fail).
                Host.UI.WriteLine($"Please remember to grant '{createdSink?.WriterIdentity}' {permissionRequest}");
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Conflict)
            {
                WriteResourceExistsError(
                    exceptionMessage: $"Cannot create '{SinkName}' in project '{Project}' because it already exists.",
                    errorId: "SinkAlreadyExists",
                    targetObject: LogName);
            }
        }