using Microsoft.Build.Utilities;
using Serilog;
public class MyTask: Task {
public override bool Execute() {
using (ILogger _logger = new LoggerConfiguration().WriteTo.MSBuild(this).CreateLogger()) {
_logger.Information("Hello from my custom Serilog-powered task");
// [...]
return true;
};
}
}
Some Serilog properties carry meaningful information for MSBuild, like message code, file and line and column numbers.
They are covered in Serilog.Sinks.MSBuild.MSBuildMessages
.