/// <summary>Snippet for UpdateSink</summary> public void UpdateSink1() { // Snippet: UpdateSink(SinkNameOneof,LogSink,FieldMask,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")); LogSink sink = new LogSink(); FieldMask updateMask = new FieldMask(); // Make the request LogSink response = configServiceV2Client.UpdateSink(sinkName, sink, updateMask); // End snippet }
public async Task GetSinkAsync() { // Snippet: GetSinkAsync(string,CallSettings) // Additional: GetSinkAsync(string,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) string formattedSinkName = ConfigServiceV2Client.FormatSinkName("[PROJECT]", "[SINK]"); // Make the request LogSink response = await configServiceV2Client.GetSinkAsync(formattedSinkName); // End snippet }
public async Task CreateSinkAsync() { // Snippet: CreateSinkAsync(string,LogSink,CallSettings) // Additional: CreateSinkAsync(string,LogSink,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) string formattedParent = ConfigServiceV2Client.FormatParentName("[PROJECT]"); LogSink sink = new LogSink(); // Make the request LogSink response = await configServiceV2Client.CreateSinkAsync(formattedParent, sink); // End snippet }
/// <summary>Snippet for GetSinkAsync</summary> public async Task GetSinkAsync() { // Snippet: GetSinkAsync(SinkNameOneof,CallSettings) // Additional: GetSinkAsync(SinkNameOneof,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")); // Make the request LogSink response = await configServiceV2Client.GetSinkAsync(sinkName); // End snippet }
/// <summary>Snippet for GetSink</summary> public void GetSink_RequestObject() { // Snippet: GetSink(GetSinkRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) GetSinkRequest request = new GetSinkRequest { SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")), }; // Make the request LogSink response = configServiceV2Client.GetSink(request); // End snippet }
/// <summary>Snippet for CreateSinkAsync</summary> public async Task CreateSinkAsync() { // Snippet: CreateSinkAsync(ParentNameOneof,LogSink,CallSettings) // Additional: CreateSinkAsync(ParentNameOneof,LogSink,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]")); LogSink sink = new LogSink(); // Make the request LogSink response = await configServiceV2Client.CreateSinkAsync(parent, sink); // End snippet }
/// <summary>Snippet for CreateSink</summary> public void CreateSink_RequestObject() { // Snippet: CreateSink(CreateSinkRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; // Make the request LogSink response = configServiceV2Client.CreateSink(request); // End snippet }
/// <summary>Snippet for UpdateSinkAsync</summary> public async Task UpdateSinkAsync1() { // Snippet: UpdateSinkAsync(SinkNameOneof,LogSink,FieldMask,CallSettings) // Additional: UpdateSinkAsync(SinkNameOneof,LogSink,FieldMask,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")); LogSink sink = new LogSink(); FieldMask updateMask = new FieldMask(); // Make the request LogSink response = await configServiceV2Client.UpdateSinkAsync(sinkName, sink, updateMask); // End snippet }
/// <summary>Snippet for GetSinkAsync</summary> public async Task GetSinkAsync_RequestObject() { // Snippet: GetSinkAsync(GetSinkRequest,CallSettings) // Additional: GetSinkAsync(GetSinkRequest,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) GetSinkRequest request = new GetSinkRequest { SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")), }; // Make the request LogSink response = await configServiceV2Client.GetSinkAsync(request); // End snippet }
/// <summary>Snippet for UpdateSinkAsync</summary> public async Task UpdateSinkAsync_RequestObject() { // Snippet: UpdateSinkAsync(UpdateSinkRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) UpdateSinkRequest request = new UpdateSinkRequest { SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")), Sink = new LogSink(), }; // Make the request LogSink response = await configServiceV2Client.UpdateSinkAsync(request); // End snippet }
/// <summary>Snippet for CreateSinkAsync</summary> public async Task CreateSinkAsync_RequestObject() { // Snippet: CreateSinkAsync(CreateSinkRequest,CallSettings) // Additional: CreateSinkAsync(CreateSinkRequest,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; // Make the request LogSink response = await configServiceV2Client.CreateSinkAsync(request); // End snippet }
// true if the process ran successfully public override bool ProcessTask() { string num = string.Empty; if (parameters.ContainsKey("num")) { num = parameters?["num"]; } Random random = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); int randomNumber = random.Next(5, 20); LogSink.Write(LogEntry.Entry($"TASK: Processing {Name}\t{randomNumber}\t{num}\r\n")); Thread.Sleep(3000); NextProcessTimeUTC = DateTime.UtcNow.AddSeconds(randomNumber); return(true); }
public void Run <TMainViewModel>() { IConfiguration configuration = _configurationBuilder.Build(); LoggerConfiguration loggerConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(configuration); RegisterViewAssembly <BlasticApplication>(); Configure(x => x.RegisterInstance(configuration)); Configure(x => x.RegisterType <TMainViewModel>()); _containerBuilder.Populate(_serviceCollection); IContainer container = _containerBuilder.Build(); LogSink logSink = container.ResolveOptional <LogSink>(); if (logSink != null) { loggerConfiguration.WriteTo.Sink(logSink); } Log.Logger = loggerConfiguration.CreateLogger(); Bootstrapper bootstrapper = new Bootstrapper( container, typeof(TMainViewModel), _viewAssemblies); SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); try { bootstrapper.Initialize(); _application.Run(); } catch (Exception exception) { Log.Error(exception, exception.Message); throw; } }
// [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}."); }
public void GetSink2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); GetSinkRequest request = new GetSinkRequest { SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new BillingName("[BILLING_ACCOUNT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.GetSink(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = client.GetSink(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task GetSinkAsync2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); GetSinkRequest request = new GetSinkRequest { SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new ProjectName("[PROJECT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.GetSinkAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogSink>(Task.FromResult(expectedResponse), null, null, null, null)); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = await client.GetSinkAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
protected override LoggingBaseServiceRequest <LogSink> GetRequest(LogSink logSink) { string formattedSinkName = PrefixProjectToSinkName(SinkName, Project); // If destinations are not given, we still have to set the destination to the existing log sink destination. // Otherwise, the API will throw error. if (GcsBucketDestination == null && BigQueryDataSetDestination == null && PubSubTopicDestination == null) { try { ProjectsResource.SinksResource.GetRequest getRequest = Service.Projects.Sinks.Get(formattedSinkName); LogSink existingSink = getRequest.Execute(); logSink.Destination = existingSink.Destination; } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { // Here we throw terminating error because the cmdlet cannot proceed without a valid sink. string exceptionMessage = $"Sink '{SinkName}' does not exist in project '{Project}'." + "Please use New-GcLogSink cmdlet to create it (Set-GcLogSink can only create a sink if you supply a destination)."; ErrorRecord errorRecord = new ErrorRecord( new ArgumentException(exceptionMessage), "SinkNotFound", ErrorCategory.ResourceUnavailable, SinkName); ThrowTerminatingError(errorRecord); } } ProjectsResource.SinksResource.UpdateRequest updateRequest = Service.Projects.Sinks.Update(logSink, formattedSinkName); if (UniqueWriterIdentity.IsPresent) { updateRequest.UniqueWriterIdentity = UniqueWriterIdentity.ToBool(); } return(updateRequest); }
public LogSinkTraceLogger(LogSink sink) { this.sink = sink; }
public static void SendTestMessage(LogSink sink) { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); sink.SendMessage(logEntry); }
private void Main() { while (thread.ThreadState != ThreadState.AbortRequested) { Task task = null; lock (tasksLock) { while (scheduledTasks.Count != 0) if (scheduledTasks.Values[0].Count == 0) { scheduledTasks.RemoveAt(0); } else { if (scheduledTasks.Keys[0] <= DateTime.Now) { List<Task> tasks = scheduledTasks.Values[0]; task = tasks[0]; tasks.RemoveAt(0); } if (task == null) { for (int i = 0; i < scheduledTasks.Count; ) if (scheduledTasks.Values[i].Count == 0) scheduledTasks.RemoveAt(i); else ++i; } break; } } if (task != null) { LogSink sessionLog = new LogSink(); task.Log.Add(sessionLog); using (new LogSession(sessionLog)) { ExecuteTask(task); } } schedulerInterrupt.WaitOne(30000, false); } }
/// <summary> /// The thread entry point for this object. This object operates on a queue /// and hence the thread will sequentially execute tasks. /// </summary> private void Main() { //The waiting thread will utilize a polling loop to check for new //scheduled tasks. This will be checked every 30 seconds. However, //when the thread is waiting for a new task, it can be interrupted. while (thread.ThreadState != ThreadState.AbortRequested) { //Check for a new task Task task = null; lock (tasksLock) { while (scheduledTasks.Count != 0) { if (scheduledTasks.Values[0].Count == 0) { //Clean all all time slots at the start of the queue which are //empty scheduledTasks.RemoveAt(0); } else { if (scheduledTasks.Keys[0] <= DateTime.Now) { List <Task> tasks = scheduledTasks.Values[0]; task = tasks[0]; tasks.RemoveAt(0); } //Do schedule queue maintenance: clean up all empty timeslots if (task == null) { for (int i = 0; i < scheduledTasks.Count;) { if (scheduledTasks.Values[i].Count == 0) { scheduledTasks.RemoveAt(i); } else { ++i; } } } break; } } } if (task != null) { LogSink sessionLog = new LogSink(); task.Log.Add(sessionLog); //Start a new log session to separate this session's events //from previous ones. try { using (new LogSession(sessionLog)) { //Set the currently executing task. currentTask = task; //Prevent the system from sleeping. Power.ExecutionState = ExecutionState.Continuous | ExecutionState.SystemRequired; task.Execute(); } } finally { //Allow the system to sleep again. Power.ExecutionState = ExecutionState.Continuous; //If the task is a recurring task, reschedule it for the next execution //time since we are done with this one. if (task.Schedule is RecurringSchedule) { ScheduleTask(task); } //If the task is an execute on restart task or run immediately task, it is //only run once and can now be restored to a manually run task else if (task.Schedule == Schedule.RunOnRestart || task.Schedule == Schedule.RunNow) { task.Schedule = Schedule.RunManually; } //Remove the actively executing task from our instance variable currentTask = null; } } //Wait for half a minute to check for the next scheduled task. schedulerInterrupt.WaitOne(30000, false); } }
public DetailsModel(LogSink logger, ContentContext dbContext) { this.Logger = logger; this.DbContext = dbContext; }
// [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(); 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. // In Powershell, use this command: // PS > Add-GcsBucketAcl <your-bucket-name> -Role OWNER -Group [email protected] myLogSink.Destination = "storage.googleapis.com/" + s_projectId; LogName logName = new LogName(s_projectId, logId); myLogSink.Filter = $"logName={logName.ToString()}AND severity<=ERROR"; ProjectName projectName = new ProjectName(s_projectId); sinkRequest.Sink = myLogSink; sinkClient.CreateSink(ParentNameOneof.From(projectName), myLogSink, RetryAWhile); Console.WriteLine($"Created sink: {sinkId}."); }
public FullOwnershipContentContext( LogSink securityLog, ContentContext context, TenancyProvider tenancyProvider) : base(securityLog, context, tenancyProvider) { }
public ContentContext(DbContextOptions <ContentContext> options, LogSink logger) : base(options) { this.Logger = logger; }
/// <summary> /// Given a log sink, returns either a create or update request that will be used by the cmdlet. /// </summary> protected abstract LoggingBaseServiceRequest <LogSink> GetRequest(LogSink logsink);
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); } }
public void Add(LogSink sink) { writers_.Add(sink); }
public AssignedContentReadingContext( LogSink securityLog, ContentContext context, TenancyProvider tenancyProvider) : base(securityLog, context, tenancyProvider) { }
public ApplicationLogViewModel(LogSink logSink) { this.logSink = logSink; Logs = new ObservableList <string>(logSink.Events); logSink.LogEventEmitted += EventSink_LogEventEmitted; }
public IndexModel(LogSink logger, ContentContext dbContext) { this.Logger = logger; this.DbContext = dbContext; }
public static bool IsCloudStorageSink(this LogSink sink) { return(sink.Destination.StartsWith(CloudStorageDestinationPrefix)); }