PostmarkTarget Class

Extends TargetWithContext to send formatted mail

Definition

Namespace: InnerDrive.Logging
Assembly: InnerDrive.Logging (in InnerDrive.Logging.dll) Version: 5.2.9017.0
C#
[TargetAttribute("PostmarkTarget")]
public class PostmarkTarget : AsyncTaskTarget, 
	IMailTarget
Inheritance
Object    Target    TargetWithLayout    TargetWithContext    AsyncTaskTarget    PostmarkTarget
Implements
IMailTarget

Remarks

For best security, use an ISecretProvider (such as the KeyVaultSecretProvider to hold the API key rather than putting it in configuration files.

You can also put the connection string in your nLog.config file. Here is the typical nLog.config for this target:

C#
<target xsi:type="PostmarkTarget"
    name = "postmark"
    apiKey = "super secret Postmark API key"
    applicationName = "Logging.Test"
    from = "application@contoso.org"
    subject = "NLog sent an email"
    to = "nerdly@contoso.com"
/>

Constructors

PostmarkTarget Creates a new instance of PostmarkTarget with the default PostmarkSender.
PostmarkTarget(IPostmarkSender, ISecretProvider, String) Creates a new instance of PostmarkTarget with a specified IPostmarkSender implementation.

Properties

ApplicationName Gets or sets the application name
BatchSize Gets or sets the number of log events that should be processed in a batch by the lazy writer thread.
(Inherited from AsyncTaskTarget)
ContextProperties Gets the array of custom attributes to be passed into the logevent context
(Inherited from TargetWithContext)
ExcludeProperties List of property names to exclude when IncludeEventProperties is true
(Inherited from TargetWithContext)
ForceLockingQueue Gets or sets whether to use the locking queue, instead of a lock-free concurrent queue The locking queue is less concurrent when many logger threads, but reduces memory allocation
(Inherited from AsyncTaskTarget)
From Gets or sets the sender email address
IncludeCallSite Gets or sets a value indicating whether to include call site (class and method name) in the LogEventInfo
(Inherited from TargetWithContext)
IncludeCallSiteStackTrace Gets or sets a value indicating whether to include source info (file name and line number) in the LogEventInfo
(Inherited from TargetWithContext)
IncludeEventProperties Gets or sets the option to include all properties from the log events
(Inherited from TargetWithContext)
IncludeGdc Gets or sets a value indicating whether to include contents of the GlobalDiagnosticsContext dictionary
(Inherited from TargetWithContext)
IncludeMdc Obsolete and replaced by IncludeScopeProperties with NLog v5. Gets or sets whether to include the contents of the MappedDiagnosticsContext-dictionary.
(Inherited from TargetWithContext)
Obsolete.
IncludeMdlc Obsolete and replaced by IncludeScopeProperties with NLog v5. Gets or sets whether to include the contents of the MappedDiagnosticsLogicalContext-properties.
(Inherited from TargetWithContext)
Obsolete.
IncludeNdc Obsolete and replaced by IncludeScopeNested with NLog v5. Gets or sets whether to include the contents of the NestedDiagnosticsContext-stack.
(Inherited from TargetWithContext)
Obsolete.
IncludeNdlc Obsolete and replaced by IncludeScopeNested with NLog v5. Gets or sets whether to include the contents of the NestedDiagnosticsLogicalContext-stack.
(Inherited from TargetWithContext)
Obsolete.
IncludeScopeNested Gets or sets whether to include the contents of the ScopeContext nested-state-stack.
(Inherited from TargetWithContext)
IncludeScopeProperties Gets or sets whether to include the contents of the ScopeContext properties-dictionary.
(Inherited from TargetWithContext)
IsInitialized Gets a value indicating whether the target has been initialized.
(Inherited from Target)
Layout
(Inherited from TargetWithContext)
LayoutWithLock NLog Layout are by default threadsafe, so multiple threads can be rendering logevents at the same time. This ensure high concurrency with no lock-congestion for the application-threads, especially when using AsyncTargetWrapper or AsyncTaskTarget. But if using custom Layout or LayoutRenderer that are not threadsafe, then this option can enabled to protect against thread-concurrency-issues. Allowing one to update to NLog 5.0 without having to fix custom/external layout-dependencies.
(Inherited from Target)
Obsolete.
LoggingConfiguration Gets the logging configuration this target is part of.
(Inherited from Target)
Name Gets or sets the name of the target.
(Inherited from Target)
OptimizeBufferReuse Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
(Inherited from Target)
Obsolete.
OverflowAction Gets or sets the action to be taken when the lazy writer thread request queue count exceeds the set limit.
(Inherited from AsyncTaskTarget)
QueueLimit Gets or sets the limit on the number of requests in the lazy writer thread request queue.
(Inherited from AsyncTaskTarget)
RetryCount How many attempts to retry the same Task, before it is aborted
(Inherited from AsyncTaskTarget)
RetryDelayMilliseconds How many milliseconds to wait before next retry (will double with each retry)
(Inherited from AsyncTaskTarget)
Subject Gets or sets the subject of the message
SyncRoot Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target)
TableStyle Gets or sets the style for the message properties table in HTML
TaskDelayMilliseconds How many milliseconds to delay the actual write operation to optimize for batching
(Inherited from AsyncTaskTarget)
TaskScheduler Task Scheduler used for processing async Tasks
(Inherited from AsyncTaskTarget)
TaskTimeoutSeconds How many seconds a Task is allowed to run before it is cancelled.
(Inherited from AsyncTaskTarget)
To Gets or sets the recipient email addresses

Methods

CaptureContextGdc Takes snapshot of GlobalDiagnosticsContext for the LogEventInfo
(Inherited from TargetWithContext)
CaptureContextMdc Obsolete and replaced by CaptureScopeContextProperties(LogEventInfo, IDictionaryString, Object) with NLog v5. Takes snapshot of MappedDiagnosticsContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
CaptureContextMdlc Obsolete and replaced by CaptureScopeContextProperties(LogEventInfo, IDictionaryString, Object) with NLog v5. Takes snapshot of MappedDiagnosticsLogicalContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
CaptureContextNdc Obsolete and replaced by CaptureScopeContextNested(LogEventInfo) with NLog v5. Takes snapshot of NestedDiagnosticsContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
CaptureContextNdlc Obsolete and replaced by CaptureScopeContextNested(LogEventInfo) with NLog v5. Takes snapshot of NestedDiagnosticsLogicalContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
CaptureScopeContextNested Takes snapshot of nested states from ScopeContext for the LogEventInfo
(Inherited from TargetWithContext)
CaptureScopeContextProperties Takes snapshot of ScopeContext dictionary for the LogEventInfo
(Inherited from TargetWithContext)
CloseTarget Closes Target by updating CancellationToken
(Inherited from AsyncTaskTarget)
Dispose Closes the target.
(Inherited from Target)
Dispose(Boolean) Releases any managed resources
(Inherited from AsyncTaskTarget)
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Flush Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target)
FlushAsync Schedules notification of when all messages has been written
(Inherited from AsyncTaskTarget)
GenerateUniqueItemName Generates a new unique name, when duplicate names are detected
(Inherited from TargetWithContext)
GetAllProperties(LogEventInfo) Creates combined dictionary of all configured properties for logEvent
(Inherited from TargetWithContext)
GetAllProperties(LogEventInfo, IDictionaryString, Object) Creates combined dictionary of all configured properties for logEvent
(Inherited from TargetWithContext)
GetContextMdc Obsolete and replaced by GetScopeContextProperties(LogEventInfo) with NLog v5. Returns the captured snapshot of MappedDiagnosticsContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
GetContextMdlc Obsolete and replaced by GetScopeContextProperties(LogEventInfo) with NLog v5. Returns the captured snapshot of MappedDiagnosticsLogicalContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
GetContextNdc Obsolete and replaced by GetScopeContextNested(LogEventInfo) with NLog v5. Returns the captured snapshot of NestedDiagnosticsContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
GetContextNdlc Obsolete and replaced by GetScopeContextNested(LogEventInfo) with NLog v5. Returns the captured snapshot of NestedDiagnosticsLogicalContext for the LogEventInfo
(Inherited from TargetWithContext)
Obsolete.
GetContextProperties(LogEventInfo) Checks if any context properties, and if any returns them as a single dictionary
(Inherited from TargetWithContext)
GetContextProperties(LogEventInfo, IDictionaryString, Object) Checks if any context properties, and if any returns them as a single dictionary
(Inherited from TargetWithContext)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetScopeContextNested Returns the captured snapshot of nested states from ScopeContext for the LogEventInfo
(Inherited from TargetWithContext)
GetScopeContextProperties Returns the captured snapshot of ScopeContext dictionary for the LogEventInfo
(Inherited from TargetWithContext)
GetTypeGets the Type of the current instance.
(Inherited from Object)
InitializeTarget
(Inherited from AsyncTaskTarget)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
MergeEventProperties Merges (copies) the event context properties from any event info object stored in parameters of the given event info object.
(Inherited from Target)
Obsolete.
PrecalculateVolatileLayouts Calls the Precalculate(LogEventInfo) on each volatile layout used by this target. This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target)
RenderLogEvent(Layout, LogEventInfo) Renders the logevent into a string-result using the provided layout
(Inherited from Target)
RenderLogEvent``1(LayoutUMP, LogEventInfo, UMP) Renders the logevent into a result-value by using the provided layout
(Inherited from Target)
ResolveService``1 Resolve from DI ServiceRepository
(Inherited from Target)
RetryFailedAsyncTask Handle cleanup after failed write operation
(Inherited from AsyncTaskTarget)
SerializeItemValue Take snapshot of a single object value
(Inherited from TargetWithContext)
SerializeMdcItem Obsolete and replaced by SerializeScopeContextProperty(LogEventInfo, String, Object, Object) with NLog v5. Take snapshot of a single object value from MappedDiagnosticsContext
(Inherited from TargetWithContext)
Obsolete.
SerializeMdlcItem Obsolete and replaced by SerializeScopeContextProperty(LogEventInfo, String, Object, Object) with NLog v5. Take snapshot of a single object value from MappedDiagnosticsLogicalContext
(Inherited from TargetWithContext)
Obsolete.
SerializeNdcItem Obsolete and replaced by SerializeScopeContextNestedState(LogEventInfo, Object, Object) with NLog v5. Take snapshot of a single object value from NestedDiagnosticsContext
(Inherited from TargetWithContext)
Obsolete.
SerializeNdlcItem Obsolete and replaced by SerializeScopeContextNestedState(LogEventInfo, Object, Object) with NLog v5. Take snapshot of a single object value from NestedDiagnosticsLogicalContext
(Inherited from TargetWithContext)
Obsolete.
SerializeScopeContextNestedState Take snapshot of a single object value from ScopeContext nested states
(Inherited from TargetWithContext)
SerializeScopeContextProperty Take snapshot of a single object value from ScopeContext dictionary
(Inherited from TargetWithContext)
ShouldIncludeProperties Check if logevent has properties (or context properties)
(Inherited from TargetWithContext)
ToString
(Inherited from Target)
Write(AsyncLogEventInfo)
(Inherited from AsyncTaskTarget)
Write(IListAsyncLogEventInfo) Block for override. Instead override WriteAsyncTask(IListLogEventInfo, CancellationToken)
(Inherited from AsyncTaskTarget)
Write(LogEventInfo) Block for override. Instead override WriteAsyncTask(LogEventInfo, CancellationToken)
(Inherited from AsyncTaskTarget)
WriteAsyncLogEvent Writes the log to the target.
(Inherited from Target)
WriteAsyncLogEvents(AsyncLogEventInfo) Writes the array of log events.
(Inherited from Target)
WriteAsyncLogEvents(IListAsyncLogEventInfo) Writes the array of log events.
(Inherited from Target)
WriteAsyncTask(IListLogEventInfo, CancellationToken) Override this to provide async task for writing a batch of logevents.
(Inherited from AsyncTaskTarget)
WriteAsyncTask(LogEventInfo, CancellationToken) Override this to provide async task for writing a single logevent.

Example

Example of how to override this method, and call custom async method
C#
protected override Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token)
{
   return CustomWriteAsync(logEvent, token);
}

private async Task CustomWriteAsync(LogEventInfo logEvent, CancellationToken token)
{
    await MyLogMethodAsync(logEvent, token).ConfigureAwait(false);
}

(Overrides AsyncTaskTarget.WriteAsyncTask(LogEventInfo, CancellationToken))
WriteAsyncThreadSafe(AsyncLogEventInfo) Write to queue without locking SyncRoot
(Inherited from AsyncTaskTarget)
WriteAsyncThreadSafe(IListAsyncLogEventInfo) Block for override. Instead override WriteAsyncTask(IListLogEventInfo, CancellationToken)
(Inherited from AsyncTaskTarget)
WriteFailedNotInitialized LogEvent is written to target, but target failed to successfully initialize Enqueue logevent for later processing when target failed to initialize because of unresolved service dependency.
(Inherited from AsyncTaskTarget)

Fields

DefaultApiKeyConfigurationSettingName Gets the default configuration setting key (in appSettings.json) that holds the API key value

See Also