AzureDevOps.Logger
0.1.0-azure-pipelines0035
See the version list below for details.
dotnet add package AzureDevOps.Logger --version 0.1.0-azure-pipelines0035
NuGet\Install-Package AzureDevOps.Logger -Version 0.1.0-azure-pipelines0035
<PackageReference Include="AzureDevOps.Logger" Version="0.1.0-azure-pipelines0035" />
paket add AzureDevOps.Logger --version 0.1.0-azure-pipelines0035
#r "nuget: AzureDevOps.Logger, 0.1.0-azure-pipelines0035"
// Install AzureDevOps.Logger as a Cake Addin
#addin nuget:?package=AzureDevOps.Logger&version=0.1.0-azure-pipelines0035&prerelease
// Install AzureDevOps.Logger as a Cake Tool
#tool nuget:?package=AzureDevOps.Logger&version=0.1.0-azure-pipelines0035&prerelease
Azure DevOps Pipeline Logger
Simple .NET package to log specific Azure DevOps commands during a pipeline run. A use-case could be when you're developing a custom console application (e.g. a CLI tool) that is used in Azure DevOps pipelines. This package enables you to send logging commands to the pipeline in a simple and easy way.
The package exposes a logger class where called methods will be converted to the appropiate log commands defined by Microsoft. For example:
logger.LogCommand("task.setvariable", "secretvalue", new Dictionary<string, string>
{
{"variable", "secret"},
{"issecret", "true"}
});
results in the following command being logged to the pipeline:
##vso[task.setvariable variable=secret;issecret=true;]secretvalue
A complete reference of logging commands can be found in the Microsoft Docs.
Features
- Log messages with supported severity levels
- Create log groups
- Log commands (examples: set variable, upload artifact)
- Set task progress
Installation
Install the NuGet package AzureDevOps.Logger. Then follow one of the registration methods below.
Method 1: Dependency injection (preferred)
Register the required services, mostly in the ConfigureServices
of the Startup
class, using the provived extension method:
services.AddAzureDevOpsLogger();
If you're using a custom DI container, make sure to register the following services and implementation:
container.AddSingleton<ILogMessageFactory, LogMessageFactory>();
container.AddSingleton<IAzDOLogger, AzDOLogger>();
After registration, the IAzDOLogger
service is ready to be injected wherever you need them, for example:
public WeatherForecastController(IAzDOLogger logger)
{
_logger = logger;
}
Method 2: Manual
You can manually create an instance of the logger with the following snippet:
var logger = new AzDOLogger(new LogMessageFactory());
Usage
The section below shows how to use the NuGet package. Please refer to the Microsoft Docs to see how the log commands will show up in your pipeline and what they do.
Log formatting commands (docs)
The Log()
method can be used to log simple formatting commands to the pipeline log with a specific severity. These logs don't show up in the pipeline results.
logger.Log(LogFormat.Section, "This is a section message");
logger.Log(LogFormat.Command, "This is a command message");
logger.Log(LogFormat.Debug, "This is a debug message");
logger.Log(LogFormat.Error, "This is a error message");
logger.Log(LogFormat.Warning, "This is a warning message");
Log group of formatting commands
The StartLogGroup()
method can be used indicate the start of a group of formatted log commands. A group can be collapsed in the pipeline log.
logger.StartLogGroup("This is a group", pipelinesLogger =>
{
pipelinesLogger.Log(LogFormat.Section, "This is a section message");
pipelinesLogger.Log(LogFormat.Command, "This is a command message");
pipelinesLogger.Log(LogFormat.Debug, "This is a debug message");
pipelinesLogger.Log(LogFormat.Error, "This is a error message");
pipelinesLogger.Log(LogFormat.Warning, "This is a warning message");
});
Log issues (docs)
The LogIssue()
method can be used to log warnings and errors to the pipeline. These will show up in the pipeline results as either warning or error. Keep in mind that this does not automatically stop a pipeline from executing like an actual error would.
Log progress command (docs)
The LogProgress
method can be used to log a progress command to the pipeline log. The progress percentage will be shown instead of the default 'task running' spinner.
logger.LogProgress("Log running taks", 10);
Log commands (docs)
For other commands, like artifact commands, you can use the LogCommand()
method. Using this method you can log all the commands that are specified in the docs.
For example, to set a variable, the following code can be used:
logger.LogCommand("task.setvariable", "secretvalue", new Dictionary<string, string>
{
{"variable", "secret"},
{"issecret", "true"}
});
The result is the following log command:
##vso[task.setvariable variable=secret;issecret=true;]secretvalue
Contributing
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 426 | 11/9/2023 |
1.0.1 | 2,146 | 1/21/2022 |
1.0.0 | 644 | 1/21/2022 |
0.1.0-azure-pipelines0035 | 464 | 1/21/2022 |
0.1.0-azure-pipelines0031 | 481 | 1/21/2022 |