Open sandboxFocus
  • TOC

Post­Sharp Documentation

Introduction

Deployment and Configuration

Adding Aspects to Code

Logging

Contracts

INotify­Property­Changed

Weak Event

XAML

Parent/Child, Visitor and Disposable

Undo/Redo

Caching

Multithreading

Developing Custom Aspects

Validating Architecture

Testing and Debugging

Miscellaneous

API Reference

Post­Sharp

Post­Sharp.​Aspects

Post­Sharp.​Aspects.​Advices

Post­Sharp.​Aspects.​Configuration

Post­Sharp.​Aspects.​Dependencies

Post­Sharp.​Aspects.​Internals

Post­Sharp.​Aspects.​Serialization

Post­Sharp.​Collections

Post­Sharp.​Constraints

Post­Sharp.​Extensibility

Post­Sharp.​Extensibility.​Build­Time­Logging

Post­Sharp.​Patterns

Post­Sharp.​Patterns.​Caching

Post­Sharp.​Patterns.​Caching.​Backends

Post­Sharp.​Patterns.​Caching.​Backends.​Azure

Post­Sharp.​Patterns.​Caching.​Backends.​Redis

Post­Sharp.​Patterns.​Caching.​Dependencies

Post­Sharp.​Patterns.​Caching.​Formatters

Post­Sharp.​Patterns.​Caching.​Implementation

Post­Sharp.​Patterns.​Caching.​Locking

Post­Sharp.​Patterns.​Caching.​Serializers

Post­Sharp.​Patterns.​Caching.​Value­Adapters

Post­Sharp.​Patterns.​Collections

Post­Sharp.​Patterns.​Collections.​Advices

Post­Sharp.​Patterns.​Contracts

Post­Sharp.​Patterns.​Diagnostics

Close­Activity­Options

Context­Id­Generation­Strategy

Custom­Record­Logging­Options

Default­Logging­Exception­Handler

Formatted­Message­Builder

ILog­Activity

ILog­Aspect

ILogging­Exception­Handler

ILog­Value­Aspect

Log­Activity2

Log­Activity<TActivity­Description>

Log­Activity­Kind

Log­Activity­Options

Log­Attribute6

Log­Attribute­Base5

Log­Exception­Attribute6

Logger

Logger­Factory­Extensions

Logging­Abstract­Source

Logging­Backend

Logging­Backend­Options

Logging­Build­Time­Configuration

Logging­Configuration­Manager

Logging­Context­Local­Configuration

Logging­Context­Local­Configuration­Scope

Logging­Context­Mismatch­Exception2

Logging­Exception2

Logging­Exception­Info

Logging­Namespace­Source

Logging­Options

Logging­Options.​Serializer2

Logging­Profile

Logging­Profile.​Serializer2

Logging­Profile­Collection3

Logging­Profile­Repository

Logging­Property

Logging­Role­Configuration

Logging­Role­Configuration­Repository

Logging­Roles

Logging­Services

Logging­Services.​Formatters2

Logging­Source­Local­State

Logging­Type­Source2

Logging­Verbosity­Configuration

Log­Level

Log­Record­Kind

Log­Record­Kind­Extensions

Log­Source

Log­Value­Attribute5

Not­Logged­Attribute2

Open­Activity­Options

Semantic­Message­Builder

Throwing­Logging­Exception­Handler

Write­Message­Options

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Core

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Asp­Net­Framework

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Diagnostic­Source

Post­Sharp.​Patterns.​Diagnostics.​Adapters.​Http­Client

Post­Sharp.​Patterns.​Diagnostics.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Application­Insights

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Audit

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Common­Logging

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Console

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Event­Source

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Log4Net

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Microsoft

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Multiplexer

Post­Sharp.​Patterns.​Diagnostics.​Backends.​NLog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Null

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Serilog

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace

Post­Sharp.​Patterns.​Diagnostics.​Backends.​Trace­Source

Post­Sharp.​Patterns.​Diagnostics.​Contexts

Post­Sharp.​Patterns.​Diagnostics.​Correlation

Post­Sharp.​Patterns.​Diagnostics.​Custom

Post­Sharp.​Patterns.​Diagnostics.​Custom.​Messages

Post­Sharp.​Patterns.​Diagnostics.​Formatters

Post­Sharp.​Patterns.​Diagnostics.​Record­Builders

Post­Sharp.​Patterns.​Diagnostics.​Threading­Instrumentation

Post­Sharp.​Patterns.​Diagnostics.​Transactions

Post­Sharp.​Patterns.​Diagnostics.​Transactions.​Model

Post­Sharp.​Patterns.​Dynamic­Advising

Post­Sharp.​Patterns.​Formatters

Post­Sharp.​Patterns.​Model

Post­Sharp.​Patterns.​Model.​Controls

Post­Sharp.​Patterns.​Model.​Type­Adapters

Post­Sharp.​Patterns.​Recording

Post­Sharp.​Patterns.​Recording.​Operations

Post­Sharp.​Patterns.​Threading

Post­Sharp.​Patterns.​Threading.​Models

Post­Sharp.​Patterns.​Utilities

Post­Sharp.​Patterns.​Xaml

Post­Sharp.​Reflection

Post­Sharp.​Reflection.​Method­Body

Post­Sharp.​Serialization

  • Article

Class LogSource

Allow to write log messages and trace the execution of activities. This class is optimized for use with C# 7.2 or later. For previous compiler versions, consider using the legacy PostSharp.Patterns.Diagnostics.LogSource.Logger class.

Inheritance
LogSource
Namespace: PostSharp.Patterns.Diagnostics
Assembly: PostSharp.Patterns.Common.dll
Syntax
[RequirePostSharp("PostSharp.Patterns.Common.Weaver", "AddCallerInfoTask", AnyTypeReference = true)]
public sealed class LogSource
Remarks

Instances of this class are immutable.

You should typically have one instance of this class per type. Use Get() or GetLogSource(ILoggerFactory2, Type) to get an instance of this class for the current type.

Properties

Name Description
Critical

Exposes methods that allow to write messages and open activities with the Critical severity.

CurrentContext
Debug

Exposes methods that allow to write messages and open activities with the Debug severity.

Default

Exposes methods that allow to write messages and open activities with the default severity of the current LogSource. The default severity is Debug, unless it has been overwritten by the WithLevels(LogLevel, LogLevel) method.

Error

Exposes methods that allow to write messages and open activities with the Error severity.

Failure

Exposes methods that allow to write messages and open activities with the default failure severity of the current LogSource. The default severity is Error, unless it has been overwritten by the WithLevels(LogLevel, LogLevel) method.

Info

Exposes methods that allow to write messages and open activities with the Info severity.

None

Exposes methods that allow to open activities with the None severity. Such activities are never displayed, but they can define properties that can be inherited to children activities and messages.

Trace

Exposes methods that allow to write messages and open activities with the Trace severity.

Warning

Exposes methods that allow to write messages and open activities with the Warning severity.

Methods

Name Description
ApplyTransactionRequirements(ref OpenActivityOptions)

Evaluates whether a transaction needs to be open for a specified OpenActivityOptions and updates its TransactionRequirement property. This method must be invoked before calling OpenActivity<T>(in T, in OpenActivityOptions). It is not automatically called.

ForCurrentType()

Gets a new LogSource keeping all the configuration of the current instance, but for the calling type.

ForSource(string)

Gets a new LogSource keeping all the configuration of the current instance, but for a source name.

ForType(Type)

Gets a new LogSource keeping all the configuration of the current instance, but for a different type.

Get()

Gets a LogSource for the calling type.

Get(string)

Gets a log source associated with a specific source name.

Get(string, string)

Gets a log source for a specified role and source name.

Get(Type, string)

Gets a log source for a specified role and Type.

IsEnabled(LogLevel)

Determines whether logging is enabled in the current LogSource for a given LogLevel.

WithLevel(LogLevel)

Exposes methods that allow to write messages and open activities with a specified LogLevel.

WithLevels(LogLevel, LogLevel)

Returns a new LogSource based on the current instance, but overrides the default logging levels.

WriteExecutionPoint()

Emits a log record with the source file and line of the caller.

  • Navigation

In this article

Properties

Methods