private static async Task SearchLog(LogSearchClient client, string compartmentId, string logGroupId, string logId)
        {
            DateTime          timeStart         = DateTime.Parse("12/09/2020 20:00:00");
            DateTime          timeEnd           = DateTime.Parse("12/09/2020 21:00:00");
            SearchLogsRequest searchLogsRequest = new SearchLogsRequest
            {
                SearchLogsDetails = new SearchLogsDetails
                {
                    SearchQuery = $"search \"{compartmentId}/{logGroupId}/{logId}\"",
                    TimeStart   = timeStart,
                    TimeEnd     = timeEnd
                },
                Limit = 5
            };

            logger.Info($"Searching log for entries between:{timeStart} to {timeEnd}");
            logger.Info("=============");
            SearchLogsResponse searchLogsResponse = await client.SearchLogs(searchLogsRequest);

            logger.Info($"Response OpcRequestId:{searchLogsResponse.OpcRequestId}");
            logger.Info($"Search Response count:{searchLogsResponse.SearchResponse.Results.Count}");
            foreach (var result in searchLogsResponse.SearchResponse.Results)
            {
                logger.Info($"data:{result.Data.ToString()}");
            }
        }
Exemple #2
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new LogSearchClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
        public static async Task MainLogging()
        {
            string compartmentId  = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
            string logGroupId     = Environment.GetEnvironmentVariable("OCI_LOG_GROUP");
            string logDisplayName = "oci-dotnet-sdk-example-log";
            // Accepts profile name and creates a auth provider based on config file
            var provider = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName);
            // Create clients for the service to enable using its APIs
            var logManagementClient = new LoggingManagementClient(provider, new ClientConfiguration());
            var logIngestionclient  = new LoggingClient(provider, new ClientConfiguration());
            var logSearchClient     = new LogSearchClient(provider, new ClientConfiguration());

            try
            {
                string logId = await CreateLog(logManagementClient, logGroupId, logDisplayName);

                //string logId = "ocid1.log.oc1.phx.amaaaaaaogrv47iah6om32dahq3g4p6sleadbnsyptckvirmilizekvjptza";
                await ListLogs(logManagementClient, logGroupId);
                await GetLog(logManagementClient, logGroupId, logId);

                // Wait for log to be accessible
                System.Threading.Thread.Sleep(50000);
                await PutLogDetails(logIngestionclient, logId);

                // Wait for PutLogs to ingest Logs
                System.Threading.Thread.Sleep(20000);
                await SearchLog(logSearchClient, compartmentId, logGroupId, logId);
                await DeleteLog(logManagementClient, logGroupId, logId);
            }
            catch (Exception e)
            {
                logger.Info($"Received exception due to {e.Message}");
            }
            finally
            {
                logManagementClient.Dispose();
                logIngestionclient.Dispose();
                logSearchClient.Dispose();
            }
        }