Permalink
Switch branches/tags
304NotModified-version-appveyor-vars 1006-mono4 1029-Writing-to-the-same-file-from-multiple-processes 2856-rawvalue-encode-layoutrenderers AppDomainWrapper-internal CouldHaveLogEventInfoParameters FileCharacteristics-struct2 JsonPropertiesJson_objectTest LoggingConfiguration-configure NetworkTarget-Tls Overhaul-contexts ReloadTests-mono TryLoadFromFilePathsException3-improve-test TypeInitializationException-tester UWP appsettings-netstandard autoload-ext-from-current-dir before-pr2363 better-debug-unittest-experience bugfix/TryLoadLoggingConfiguration-catch bugfix/archiving-removes-to-many-files-NLOG4_0_1 bugfix/archiving-removes-to-many-files cacheobject callsite-filter-namespacce contentfiles-nuspec coreCLR-autodetect-tests coreCLR-getcurrentclasslogger-activator coreCLR-json coreCLR-test3 coreCLR coreclr-artifacts+codecov coreclr-artifacts db-parameters-type dbtarget-dbtypes-sept2018_backup2 dbtarget-dbtypes-sept2018 defaultjsonser-objects dev feature/inner-text-variables feature/target-layout-render-aliasses fix-appveyor-versioning-env fix-callsite-async-1812 fix-mono-reload-tests generate-markdown-docs ilogger2 internal-log-level-backup internallogger-events2 interpolated-string-support interpolated-string-support2 jojosardez-feature-and-bugfix/2249-layout-renderer-macro-as-separator jv-configure_lambda-method licenseUrl-https master mono3-2016 no-crash-on-files-not-match-DateAndSequence-4.3.7 perf-remove-stuff performance-tweaks-#1594 pr-1194 pr-1222-mono pr-1426-async-Identity-fail pr/1660-b pr/1660 pr/1683 skip-tests snakefoot2/XmlLayout sonarcloud-nlog-project structured-test-cases test-queryperformance this.getLogger tryout-layoutrender-in-parameter uwp-appveyor variables-IgnoreCase working-dir-xml-config-candidate xamarin-appveyor-new xml-layout xmlBuilder
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (100 sloc) 4.26 KB
//
// Copyright (c) 2004-2018 Jaroslaw Kowalski <jaak@jkowalski.net>, Kim Christensen, Julian Verdurmen
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of Jaroslaw Kowalski nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
namespace NLog.Time
{
using System;
using Config;
using Internal;
/// <summary>
/// Defines source of current time.
/// </summary>
[NLogConfigurationItem]
public abstract class TimeSource
{
private static TimeSource currentSource = new FastLocalTimeSource();
/// <summary>
/// Gets current time.
/// </summary>
public abstract DateTime Time { get; }
/// <summary>
/// Gets or sets current global time source used in all log events.
/// </summary>
/// <remarks>
/// Default time source is <see cref="FastLocalTimeSource"/>.
/// </remarks>
public static TimeSource Current
{
get => currentSource;
set => currentSource = value;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
var targetAttribute = GetType().GetCustomAttribute<TimeSourceAttribute>();
if (targetAttribute != null)
{
return targetAttribute.Name + " (time source)";
}
return GetType().Name;
}
/// <summary>
/// Converts the specified system time to the same form as the time value originated from this time source.
/// </summary>
/// <param name="systemTime">The system originated time value to convert.</param>
/// <returns>
/// The value of <paramref name="systemTime"/> converted to the same form
/// as time values originated from this source.
/// </returns>
/// <remarks>
/// <para>
/// There are situations when NLog have to compare the time originated from TimeSource
/// to the time originated externally in the system.
/// To be able to provide meaningful result of such comparisons the system time must be expressed in
/// the same form as TimeSource time.
/// </para>
/// <para>
/// Examples:
/// - If the TimeSource provides time values of local time, it should also convert the provided
/// <paramref name="systemTime"/> to the local time.
/// - If the TimeSource shifts or skews its time values, it should also apply
/// the same transform to the given <paramref name="systemTime"/>.
/// </para>
/// </remarks>
public abstract DateTime FromSystemTime(DateTime systemTime);
}
}