Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions src/Cake.Common/Diagnostics/LoggingAliases.Disposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Diagnostics;

namespace Cake.Common.Diagnostics;

public static partial class LoggingAliases
{
/// <summary>
/// Sets the log verbosity to quiet and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">the context.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (QuietVerbosity())
/// {
/// Error("Show me.");
/// Warning("Hide me.");
/// Information("Hide me.");
/// Verbose("Hide me.");
/// Debug("Hide me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable QuietVerbosity(this ICakeContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.QuietVerbosity();
}

/// <summary>
/// Sets the log verbosity to minimal and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">the context.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (MinimalVerbosity())
/// {
/// Error("Show me.");
/// Warning("Show me.");
/// Information("Hide me.");
/// Verbose("Hide me.");
/// Debug("Hide me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable MinimalVerbosity(this ICakeContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.MinimalVerbosity();
}

/// <summary>
/// Sets the log verbosity to normal and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">the context.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (NormalVerbosity())
/// {
/// Error("Show me.");
/// Warning("Show me.");
/// Information("Show me.");
/// Verbose("Hide me.");
/// Debug("Hide me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable NormalVerbosity(this ICakeContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.NormalVerbosity();
}

/// <summary>
/// Sets the log verbosity to verbose and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">the context.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (VerboseVerbosity())
/// {
/// Error("Show me.");
/// Warning("Show me.");
/// Information("Show me.");
/// Verbose("Show me.");
/// Debug("Hide me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable VerboseVerbosity(this ICakeContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.VerboseVerbosity();
}

/// <summary>
/// Sets the log verbosity to diagnostic and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">the context.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (DiagnosticVerbosity())
/// {
/// Error("Show me.");
/// Warning("Show me.");
/// Information("Show me.");
/// Verbose("Show me.");
/// Debug("Show me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable DiagnosticVerbosity(this ICakeContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.DiagnosticVerbosity();
}

/// <summary>
/// Sets the log verbosity as specified and returns a disposable that restores the log verbosity on dispose.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="verbosity">The verbosity.</param>
/// <returns>A disposable that restores the log verbosity.</returns>
/// <example>
/// <code>
/// using (DiagnosticVerbosity())
/// {
/// Error("Show me.");
/// Warning("Show me.");
/// Information("Show me.");
/// Verbose("Show me.");
/// Debug("Show me.");
/// }
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbosity")]
public static IDisposable WithVerbosity(this ICakeContext context, Verbosity verbosity)
{
ArgumentNullException.ThrowIfNull(context);
return context.Log.WithVerbosity(verbosity);
}
}
189 changes: 189 additions & 0 deletions src/Cake.Common/Diagnostics/LoggingAliases.Formattable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
using System;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.Diagnostics;

namespace Cake.Common.Diagnostics;

public static partial class LoggingAliases
{
/// <summary>
/// Writes an error message to the log using the specified format information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattable">The string to be formatted.</param>
/// <example>
/// <code>
/// Error($"Hello {"World"}! Today is an {DateTime.Now:dddd}");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Error")]
public static void Error(this ICakeContext context, FormattableString formattable)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Error(formattable);
}

/// <summary>
/// Writes an warning message to the log using the specified format information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattable">The string to be formatted.</param>
/// <example>
/// <code>
/// Warning($"Hello {"World"}! Today is an {DateTime.Now:dddd}");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Warning")]
public static void Warning(this ICakeContext context, FormattableString formattable)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Warning(formattable);
}

/// <summary>
/// Writes an informational message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattable">The string to be formatted.</param>
/// <example>
/// <code>
/// Information($"Hello {"World"}! Today is an {DateTime.Now:dddd}");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Information")]
public static void Information(this ICakeContext context, FormattableString formattable)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Information(formattable);
}

/// <summary>
/// Writes an verbose message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattable">The string to be formatted.</param>
/// <example>
/// <code>
/// Verbose($"Hello {"World"}! Today is an {DateTime.Now:dddd}");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbose")]
public static void Verbose(this ICakeContext context, FormattableString formattable)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Verbose(formattable);
}

/// <summary>
/// Writes an debug message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattable">The string to be formatted.</param>
/// <example>
/// <code>
/// Debug($"Hello {"World"}! Today is an {DateTime.Now:dddd}");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Debug")]
public static void Debug(this ICakeContext context, FormattableString formattable)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Debug(formattable);
}

/// <summary>
/// Writes an error message to the log using the specified format information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattableLogAction">The log action.</param>
/// <example>
/// <code>
/// Error(logAction => logAction($"Hello {"World"}! Today is an {DateTime.Now:dddd}"));
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Error")]
public static void Error(this ICakeContext context, FormattableLogAction formattableLogAction)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Error(formattableLogAction);
}

/// <summary>
/// Writes an warning message to the log using the specified format information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattableLogAction">The log action.</param>
/// <example>
/// <code>
/// Warning(logAction => logAction($"Hello {"World"}! Today is an {DateTime.Now:dddd}"));
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Warning")]
public static void Warning(this ICakeContext context, FormattableLogAction formattableLogAction)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Warning(formattableLogAction);
}

/// <summary>
/// Writes an informational message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattableLogAction">The log action.</param>
/// <example>
/// <code>
/// Information(logAction => logAction($"Hello {"World"}! Today is an {DateTime.Now:dddd}"));
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Information")]
public static void Information(this ICakeContext context, FormattableLogAction formattableLogAction)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Information(formattableLogAction);
}

/// <summary>
/// Writes an verbose message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattableLogAction">The log action.</param>
/// <example>
/// <code>
/// Verbose(logAction => logAction($"Hello {"World"}! Today is an {DateTime.Now:dddd}"));
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Verbose")]
public static void Verbose(this ICakeContext context, FormattableLogAction formattableLogAction)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Verbose(formattableLogAction);
}

/// <summary>
/// Writes an debug message to the log using the specified formattable string.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="formattableLogAction">The log action.</param>
/// <example>
/// <code>
/// Debug(logAction => logAction($"Hello {"World"}! Today is an {DateTime.Now:dddd}"));
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Debug")]
public static void Debug(this ICakeContext context, FormattableLogAction formattableLogAction)
{
ArgumentNullException.ThrowIfNull(context);
context.Log.Debug(formattableLogAction);
}
}
Loading
Loading