Skip to content

Commit 41b5e84

Browse files
committed
Logging: adding more info to README.md.
1 parent f93a48e commit 41b5e84

File tree

18 files changed

+136
-8
lines changed

18 files changed

+136
-8
lines changed

Diagnostics/PostSharp.Samples.Audit.Extended/ExtendedAuditRecordBuilder.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ public ExtendedAuditRecordBuilder(AuditBackend backend) : base(backend)
1515
protected override AuditRecord CreateRecord(LoggingContext context, ref LogRecordInfo recordInfo,
1616
ref LogMemberInfo memberInfo)
1717
{
18+
// Return an instance of our own extended class.
1819
return new ExtendedAuditRecord(context.Source.SourceType, memberInfo.MemberName, recordInfo.RecordKind);
1920
}
2021

2122
public override void SetParameter<T>(int index, string parameterName, ParameterDirection direction, string typeName,
2223
T value,
2324
IFormatter<T> formatter)
2425
{
26+
base.SetParameter(index, parameterName, direction, typeName, value, formatter);
27+
28+
// When the parameter is a business object, add it to the list of correlated business objects.
2529
var businessObject = value as BusinessObject;
2630

2731
if (businessObject != null)
2832
((ExtendedAuditRecord) CurrentRecord).RelatedBusinessObjects.Add(businessObject);
2933

30-
base.SetParameter(index, parameterName, direction, typeName, value, formatter);
3134
}
3235
}
3336
}

Diagnostics/PostSharp.Samples.Audit.Extended/PurchaseOrder.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace PostSharp.Samples.Audit.Extended
44
{
55
public class PurchaseOrder : BusinessObject
66
{
7+
8+
// Note the Audit aspect on this method.
79
[Audit]
810
public void AssignTo(Employee employee)
911
{

Diagnostics/PostSharp.Samples.Audit/PurchaseOrder.cs

+3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ namespace PostSharp.Samples.Audit
44
{
55
public class PurchaseOrder : BusinessObject
66
{
7+
8+
// Not the Audit aspect on this method.
79
[Audit]
810
public void Approve(string comment = null)
911
{
12+
// Details skipped.
1013
}
1114
}
1215
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
using PostSharp.Patterns.Diagnostics.Backends.CommonLogging;
55
using PostSharp.Samples.Logging.BusinessLogic;
66

7+
// Adds logging to all methods of this project.
78
[assembly: Log]
89

910
namespace PostSharp.Samples.Logging.CommonLogging
1011
{
11-
[Log(AttributeExclude = true)]
12+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1213
internal class Program
1314
{
1415
private static void Main(string[] args)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to Common.Logging.
22
Here Common.Logging is configured to direct outputs to the system console.
33

4+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
5+
namespace and only simulate some business logic.
6+
7+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
8+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
9+
code is allowed before the logging service is initialized.
10+
11+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
12+
output in the log.
13+
14+
## Viewing the log
15+
16+
In this example, the log is only printed to the console. No file is created.
17+
18+
419
## Documentation
520

621
[Logging to the Common.Logging](http://doc.postsharp.net/common-logging)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
using PostSharp.Patterns.Diagnostics.Backends.Console;
33
using PostSharp.Samples.Logging.BusinessLogic;
44

5+
// Add logging to all methods of the current project.
56
[assembly: Log]
67

78
namespace PostSharp.Samples.Logging.Console
89
{
9-
[Log(AttributeExclude = true)]
10+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1011
internal class Program
1112
{
1213
private static void Main(string[] args)

Diagnostics/PostSharp.Samples.Logging.Console/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to the system console.
22

3+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
4+
namespace and only simulate some business logic.
5+
6+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
7+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
8+
code is allowed before the logging service is initialized.
9+
10+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
11+
output in the log.
12+
13+
## Viewing the log
14+
15+
In this example, the log is only printed to the console. No file is created.
16+
317

418
## Documentation
519

Diagnostics/PostSharp.Samples.Logging.CustomBackend.ServiceStack/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using PostSharp.Samples.Logging.BusinessLogic;
33
using ServiceStack.Logging;
44

5+
// Add logging to all methods of this project.
56
[assembly: Log(AttributePriority = 0)]
7+
8+
// Exclude logging from the PostSharp.Samples.Logging.CustomBackend.ServiceStack namespace.
69
[assembly:
710
Log(AttributePriority = 1, AttributeExclude = true,
811
AttributeTargetTypes = "PostSharp.Samples.Logging.CustomBackend.ServiceStack.*")]

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
using PostSharp.Patterns.Diagnostics.Backends.EventSource;
33
using PostSharp.Samples.Logging.BusinessLogic;
44

5+
// Add logging to all methods of this project.
56
[assembly: Log]
67

78
namespace PostSharp.Samples.Logging.Etw
89
{
9-
[Log(AttributeExclude = true)]
10+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1011
internal class Program
1112
{
1213
private static void Main(string[] args)

Diagnostics/PostSharp.Samples.Logging.Etw/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to ETW.
22

3+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
4+
namespace and only simulate some business logic.
5+
6+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
7+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
8+
code is allowed before the logging service is initialized.
9+
10+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
11+
output in the log.
12+
13+
## Viewing the log
14+
15+
To view the log produced by this example, you need to attach a log collector:
16+
17+
1. Download PerfView from https://www.microsoft.com/en-us/download/details.aspx?id=28567.
18+
19+
2. Execute: perfview.exe collect -OnlyProviders *PostSharp-Patterns-Diagnostics
20+
21+
3. Execute this program.
22+
23+
4. In PerfView, click 'Stop collecting', then in the PerfView tree view click 'PerfViewData.etl.zip' and finally 'Events'.
24+
325

426
## Documentation
527

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
using PostSharp.Patterns.Diagnostics.Backends.Log4Net;
55
using PostSharp.Samples.Logging.BusinessLogic;
66

7+
// Add logging to all methods of this project.
78
[assembly: Log]
89

910

1011
namespace PostSharp.Samples.Logging.Log4Net
1112
{
12-
[Log(AttributeExclude = true)]
13+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1314
internal class Program
1415
{
1516
private static void Main(string[] args)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to log4net.
22

33

4+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
5+
namespace and only simulate some business logic.
6+
7+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
8+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
9+
code is allowed before the logging service is initialized.
10+
11+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
12+
output in the log.
13+
14+
## Viewing the log
15+
16+
After you execute the file, you should find the log in the `bin\Debug` directory.
17+
18+
419
## Documentation
520

621
[Logging to the log4net](http://doc.postsharp.net/log4net)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
using PostSharp.Patterns.Diagnostics.Backends.Loupe;
55
using PostSharp.Samples.Logging.BusinessLogic;
66

7+
// Add logging to all methods of this project.
78
[assembly: Log]
89

910
namespace PostSharp.Samples.Logging.Loupe
1011
{
11-
[Log(AttributeExclude = true)]
12+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1213
internal class Program
1314
{
1415
private static void Main(string[] args)

Diagnostics/PostSharp.Samples.Logging.Loupe/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to Loupe from Gibraltar.
2+
3+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
4+
namespace and only simulate some business logic.
5+
6+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
7+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
8+
code is allowed before the logging service is initialized.
9+
10+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
11+
output in the log.
12+
13+
## Viewing the log
14+
15+
216
The application automatically opens an empty window of the Loupe Viewer. You should then see a Loupe desktop notification saying that a new
317
session is available. Click on this notification to open the log, and ignore the empty window that first opened.
418

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
using PostSharp.Samples.Logging.BusinessLogic;
77
using LogLevel = NLog.LogLevel;
88

9+
// Add logging to all methods of this project.
910
[assembly: Log]
1011

1112
namespace PostSharp.Samples.Logging.NLog
1213
{
13-
[Log(AttributeExclude = true)]
14+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1415
internal static class Program
1516
{
1617
private static void Main(string[] args)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to NLog.
22

33

4+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
5+
namespace and only simulate some business logic.
6+
7+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
8+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
9+
code is allowed before the logging service is initialized.
10+
11+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
12+
output in the log.
13+
14+
## Viewing the log
15+
16+
17+
After you execute the file, you should find the log in the `bin\Debug` directory.
18+
419
## Documentation
520

621
[Logging to the log4net](http://doc.postsharp.net/nlog)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
using PostSharp.Samples.Logging.BusinessLogic;
44
using Serilog;
55

6+
// Add logging to all methods of this project.
67
[assembly: Log]
78

89
namespace PostSharp.Samples.Logging.Serilog
910
{
10-
[Log(AttributeExclude = true)]
11+
[Log(AttributeExclude = true)] // Removes logging from the Program class itself.
1112
internal class Program
1213
{
1314
private static void Main(string[] args)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
This example demonstrates how to configure the PostSharp Logging aspect so that it prints its output to Serilog.
22

33

4+
`Program.cs` is the only interesting one file. The other classes are members of the `PostSharp.Samples.Logging.BusinessLogic`
5+
namespace and only simulate some business logic.
6+
7+
The `[assembly: Log]` custom attribute in `Program.cs` adds logging to the whole project. However, the `[Log(AttributeExclude = true)]`
8+
attribute on the `Program` class prevents the `Program` class itself from being logged. This is required because no logged
9+
code is allowed before the logging service is initialized.
10+
11+
The first line of the `Program.Main` method initializes PostSharp Logging. The method then executes the business code to produce some
12+
output in the log.
13+
14+
## Viewing the log
15+
16+
17+
After you execute the file, you should find the log in the `bin\Debug` directory.
18+
419
## Documentation
520

621
[Logging to the Serilog](http://doc.postsharp.net/serilog)

0 commit comments

Comments
 (0)