Ejemplo n.º 1
0
            public void TestUpdateSink()
            {
                string      sinkId   = "sinkForTestUpdateSink" + RandomName();
                string      logId    = "logForTestUpdateSink" + RandomName();
                string      newLogId = "newlogForTestUpdateSink" + RandomName();
                LogSinkName sinkName = new LogSinkName(_projectId, sinkId);
                string      message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                _logsToDelete.Add(newLogId);
                // Try creating logs with log entries.
                Run("create-log-entry", logId, message).AssertSucceeded();
                Run("create-log-entry", newLogId, message).AssertSucceeded();
                Run("create-sink", sinkId, logId).AssertSucceeded();
                // Try updating sink.
                Run("update-sink", sinkId, newLogId).AssertSucceeded();
                // Get sink to confirm that log has been updated.
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(sinkName);
                var currentLog = results.Filter;

                Assert.Contains(newLogId, currentLog);
            }
Ejemplo n.º 2
0
        // [END list_log_entries]

        // [START create_log_sink]
        private void CreateSink(string sinkId, string logId)
        {
            var sinkClient = ConfigServiceV2Client.Create();
            CreateSinkRequest sinkRequest = new CreateSinkRequest();
            LogSink           myLogSink   = new LogSink();
            string            sinkName    = $"projects/{s_projectId}/sinks/{sinkId}";

            myLogSink.Name = sinkId;

            // This creates a sink using a Google Cloud Storage bucket
            // named the same as the projectId.
            // This requires editing the bucket's permissions to add the Entity Group
            // named '*****@*****.**' with 'Owner' access for the bucket.
            // If this is being run with a Google Cloud service account,
            // that account will need to be granted 'Owner' access to the Project.
            myLogSink.Destination = "storage.googleapis.com/" + s_projectId;
            string logName = $"projects/{s_projectId}/logs/{logId}";

            myLogSink.Filter   = $"logName={logName}AND severity<=ERROR";
            sinkRequest.Parent = $"projects/{s_projectId}";
            sinkRequest.Sink   = myLogSink;
            sinkClient.CreateSink(sinkRequest.Parent, myLogSink);
            _out.WriteLine($"Created sink: {sinkId}.");
        }