Skip to content

Commit

Permalink
Merge pull request #23 from serilog/dev
Browse files Browse the repository at this point in the history
2.1.0 Release
  • Loading branch information
nblumhardt authored Nov 22, 2016
2 parents 350f662 + 030293f commit 7d4f169
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 113 deletions.
38 changes: 30 additions & 8 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
echo "build: Build started"

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore --no-cache

$branch = $(git symbolic-ref --short -q HEAD)
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"]
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]

foreach ($src in ls src/Serilog.*) {
echo "build: Version suffix is $suffix"

foreach ($src in ls src/*) {
Push-Location $src

& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$suffix
echo "build: Packaging project in $src"

& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/Serilog.*.Tests) {
foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

& dotnet test -c Release
echo "build: Building performance test project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
Push-Location $test

echo "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}

Pop-Location
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ deploy:
branch: /^(master|dev)$/
- provider: GitHub
auth_token:
secure: ggZTqqV1z0xecDoQbeoy3A7xikShCt9FWZIGp95dG9Fo0p5RAT9oGU0ZekHfUIwk
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
Expand Down
7 changes: 7 additions & 0 deletions serilog-sinks-email.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{340DBC35-BD0
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{70D17E86-9325-4228-8512-547B3E0774A1}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Email.Tests", "test\Serilog.Sinks.Email.Tests\Serilog.Sinks.Email.Tests.xproj", "{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,11 +32,16 @@ Global
{37082D9A-C3C9-490E-8AB9-FED496F5A70B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37082D9A-C3C9-490E-8AB9-FED496F5A70B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37082D9A-C3C9-490E-8AB9-FED496F5A70B}.Release|Any CPU.Build.0 = Release|Any CPU
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{37082D9A-C3C9-490E-8AB9-FED496F5A70B} = {340DBC35-BD09-414B-818C-978FBCA4CDF1}
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97} = {70D17E86-9325-4228-8512-547B3E0774A1}
EndGlobalSection
EndGlobal
33 changes: 1 addition & 32 deletions src/Serilog.Sinks.Email/Sinks/Email/EmailSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,6 @@ protected override void Dispose(bool disposing)
_smtpClient.Dispose();
}

protected override void EmitBatch(IEnumerable<LogEvent> events)
{
if (events == null)
throw new ArgumentNullException(nameof(events));
var payload = new StringWriter();

foreach (var logEvent in events)
{
_textFormatter.Format(logEvent, payload);
}

var mailMessage = new MailMessage
{
From = new MailAddress(_connectionInfo.FromEmail),
Subject = _connectionInfo.EmailSubject,
Body = payload.ToString(),
BodyEncoding = Encoding.UTF8,
SubjectEncoding = Encoding.UTF8,
IsBodyHtml = _connectionInfo.IsBodyHtml
};

foreach (var recipient in _connectionInfo.ToEmail.Split(",;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
mailMessage.To.Add(recipient);
}

_smtpClient.Send(mailMessage);
}

#if NET45
/// <summary>
/// Emit a batch of log events, running asynchronously.
/// </summary>
Expand All @@ -132,9 +102,9 @@ protected override void EmitBatch(IEnumerable<LogEvent> events)
/// not both.</remarks>
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
{

if (events == null)
throw new ArgumentNullException(nameof(events));

var payload = new StringWriter();

foreach (var logEvent in events)
Expand All @@ -159,7 +129,6 @@ protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)

await _smtpClient.SendMailAsync(mailMessage);
}
#endif

private SmtpClient CreateSmtpClient()
{
Expand Down
36 changes: 4 additions & 32 deletions src/Serilog.Sinks.Email/Sinks/Email/MailKitEmailSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,6 @@ private MimeKit.MimeMessage CreateMailMessage(string payload)
return mailMessage;
}

protected override void EmitBatch(IEnumerable<LogEvent> events)
{
if (events == null)
throw new ArgumentNullException(nameof(events));

var payload = new StringWriter();

foreach (var logEvent in events)
{
_textFormatter.Format(logEvent, payload);
}

var mailMessage = CreateMailMessage(payload.ToString());

try
{
using (var smtpClient = OpenConnectedSmtpClient())
{
smtpClient.Send(mailMessage);
smtpClient.Disconnect(quit: false);
}
}
catch(Exception ex)
{
SelfLog.WriteLine("Failed to send email: {0}", ex.ToString());
}
}

/// <summary>
/// Emit a batch of log events, running asynchronously.
/// </summary>
Expand Down Expand Up @@ -150,17 +122,17 @@ private SmtpClient OpenConnectedSmtpClient()
var smtpClient = new SmtpClient();
if (!string.IsNullOrWhiteSpace(_connectionInfo.MailServer))
{
smtpClient.Connect(
_connectionInfo.MailServer, _connectionInfo.Port,
useSsl: _connectionInfo.EnableSsl);

if (_connectionInfo.NetworkCredentials != null)
{
smtpClient.Authenticate(
Encoding.UTF8,
_connectionInfo.NetworkCredentials.GetCredential(
_connectionInfo.MailServer, _connectionInfo.Port, "smtp"));
}

smtpClient.Connect(
_connectionInfo.MailServer, _connectionInfo.Port,
useSsl: _connectionInfo.EnableSsl);
}
return smtpClient;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.Email/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "2.1.0-*",
"description": "The file sink for Serilog",
"authors": [ "Serilog Contributors" ],
"packOptions": {
Expand Down Expand Up @@ -27,7 +27,7 @@
},
"netstandard1.3": {
"dependencies": {
"MailKit": "1.4.0",
"MailKit": "1.4.2",
"System.Linq": "4.1.0",
"System.Threading": "4.0.11"
},
Expand Down
79 changes: 41 additions & 38 deletions test/Serilog.Sinks.Email.Tests/project.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
{
"version": "2.0.0",
"testRunner": "xunit",
"dependencies": {
"Serilog": "2.0.0",
"xunit": "2.2.0-*",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Serilog.Sinks.Email": { "target": "project" }
},
"frameworks": {
"net4.5.2": {
"buildOptions": {
"keyFile": "../../assets/Serilog.snk",
"define": [ "SYSTEM_NET" ]
},
"frameworkAssemblies": {
"System.Configuration": ""
}
},
"netcoreapp1.0": {
"buildOptions": {
"keyFile": "../../assets/Serilog.snk",
"define": [ "MAIL_KIT" ]
},
"imports": [
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"MailKit": "1.4.0",
"System.Linq": "4.1.0",
"System.Threading": "4.0.11"
}
}
}
"version": "2.0.0",
"testRunner": "xunit",

"dependencies": {
"Serilog": "2.0.0",
"xunit": "2.2.0-*",
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Serilog.Sinks.Email": { "target": "project" }
},

"buildOptions": {
"keyFile": "../../assets/Serilog.snk"
},

"frameworks": {
"net4.5.2": {
"buildOptions": {
"define": [ "SYSTEM_NET" ]
},
"frameworkAssemblies": {
"System.Configuration": ""
}
},
"netcoreapp1.0": {
"buildOptions": {
"define": [ "MAIL_KIT" ]
},
"imports": [
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"System.Linq": "4.1.0",
"System.Threading": "4.0.11"
}
}
}
}

0 comments on commit 7d4f169

Please sign in to comment.