Skip to content

Commit eced207

Browse files
committed
Minor changes.
1 parent d2482d4 commit eced207

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

Diagnostics/PostSharp.Samples.Logging.Console/Program.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private static void Main(string[] args)
1515
// Configure PostSharp Logging to output logs to the console.
1616
LoggingServices.DefaultBackend = new ConsoleLoggingBackend();
1717

18+
1819
// Simulate some business logic.
1920
QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
2021
}

Diagnostics/PostSharp.Samples.Logging.ElasticStack/ClientExample/Program.cs

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class Program
1818
private static async Task Main()
1919
{
2020
using (var logger = new LoggerConfiguration()
21-
.Enrich.WithProperty("Application", "PostSharp.Samples.Diagnostics.ElasticStack.ClientExample")
21+
.Enrich.WithProperty("Application", "PostSharp.Samples.Logging.ElasticStack.ClientExample")
2222
.MinimumLevel.Debug()
2323
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
2424
{
@@ -42,13 +42,8 @@ private static async Task Main()
4242
LoggingServices.DefaultBackend = backend;
4343

4444

45-
using (logSource.Debug.OpenActivity(Formatted("Running the client"), new OpenActivityOptions
46-
{
47-
Properties = new[]
48-
{
49-
new LoggingProperty("User", "Gaius Julius Caesar") {IsBaggage = true}
50-
}
51-
}))
45+
using (logSource.Debug.OpenActivity(Formatted("Running the client"),
46+
new OpenActivityOptions { Properties = new[] { new LoggingProperty("User", "Gaius Julius Caesar") {IsBaggage = true} } }))
5247
{
5348
await QueueProcessor.ProcessQueue(".\\My\\Queue");
5449
}

Diagnostics/PostSharp.Samples.Logging.ElasticStack/ClientExample/QueueProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static QueueProcessor()
1919

2020
public static async Task ProcessQueue(string queuePath)
2121
{
22-
await ProcessItem(new QueueItem(1, Verb.Create, "orange"));
22+
await ProcessItem(new QueueItem(1, Verb.Create, "grapefruit"));
2323
await ProcessItem(new QueueItem(2, Verb.Create, "pear"));
2424
await ProcessItem(new QueueItem(3, Verb.Create, "grape"));
2525
await ProcessItem(new QueueItem(1, Verb.Get));

Diagnostics/PostSharp.Samples.Logging.ElasticStack/MicroserviceExample/Controllers/ValuesController.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Microsoft.AspNetCore.Mvc;
2+
using PostSharp.Patterns.Diagnostics;
3+
using static PostSharp.Patterns.Diagnostics.SemanticMessageBuilder;
24
using System;
35
using System.Collections.Concurrent;
46
using System.Collections.Generic;
@@ -9,6 +11,8 @@ namespace MicroserviceExample.Controllers
911
[ApiController]
1012
public class ValuesController : ControllerBase
1113
{
14+
static readonly LogSource logSource = LogSource.Get();
15+
1216
private readonly ConcurrentDictionary<int, string> values = new ConcurrentDictionary<int, string>();
1317

1418
public ValuesController()
@@ -48,6 +52,8 @@ public void Put(int id, [FromBody] string value)
4852
throw new ArgumentOutOfRangeException(nameof(value));
4953
}
5054

55+
logSource.Debug.EnabledOrNull?.Write(Semantic("SetValue", ("Id", id), ("Value", value)));
56+
5157
this.values[id] = value;
5258
}
5359

@@ -60,6 +66,8 @@ public void Post(int id, [FromBody] string value)
6066
throw new ArgumentOutOfRangeException(nameof(value));
6167
}
6268

69+
logSource.Debug.EnabledOrNull?.Write(Semantic("AddValue", ("Id", id), ("Value", value)));
70+
6371
if (!this.values.TryAdd(id, value))
6472
{
6573
this.Conflict();

Diagnostics/PostSharp.Samples.Logging.ElasticStack/MicroserviceExample/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void Main(string[] args)
2121
{
2222

2323
using (var logger = new LoggerConfiguration()
24-
.Enrich.WithProperty("Application", "PostSharp.Samples.Diagnostics.ElasticStack.MicroserviceExample")
24+
.Enrich.WithProperty("Application", "PostSharp.Samples.Logging.ElasticStack.MicroserviceExample")
2525
.MinimumLevel.Debug()
2626
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))
2727
{
@@ -51,8 +51,8 @@ public static void Main(string[] args)
5151
LoggingServices.Formatters.Register(new ObjectResultFormatter());
5252

5353
// Log only warnings by default, except for 10% randomly chosen requests.
54-
SampledLoggingActionFilter.Initialize(backend);
55-
LoggingServices.DefaultBackend.DefaultVerbosity.SetMinimalLevel(LogLevel.Warning);
54+
//SampledLoggingActionFilter.Initialize(backend);
55+
//LoggingServices.DefaultBackend.DefaultVerbosity.SetMinimalLevel(LogLevel.Warning);
5656

5757

5858

0 commit comments

Comments
 (0)