Skip to content

Commit 1f43ffb

Browse files
committed
Default Logging sample for NServiceBus 10 #7321
1 parent a95c410 commit 1f43ffb

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29728.190
5+
MinimumVisualStudioVersion = 15.0.26730.12
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{48F718EE-6C45-41BA-80EC-81BF34D4A623}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{48F718EE-6C45-41BA-80EC-81BF34D4A623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{48F718EE-6C45-41BA-80EC-81BF34D4A623}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
EndGlobalSection
16+
GlobalSection(SolutionProperties) = preSolution
17+
HideSolutionNode = FALSE
18+
EndGlobalSection
19+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
using NServiceBus;
3+
using NServiceBus.Logging;
4+
5+
public class MyHandler :
6+
IHandleMessages<MyMessage>
7+
{
8+
static ILog log = LogManager.GetLogger<MyHandler>();
9+
10+
public Task Handle(MyMessage message, IMessageHandlerContext context)
11+
{
12+
log.Info("Hello from MyHandler");
13+
return Task.CompletedTask;
14+
}
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using NServiceBus;
2+
3+
public class MyMessage :
4+
IMessage
5+
{
6+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using NServiceBus;
4+
using Microsoft.Extensions.Hosting;
5+
6+
Console.Title = "LoggingDefault";
7+
8+
var host = Host.CreateDefaultBuilder(args)
9+
.UseConsoleLifetime()
10+
.UseNServiceBus(_ =>
11+
{
12+
#region ConfigureLogging
13+
var defaultFactory = NServiceBus.Logging.LogManager.Use<NServiceBus.Logging.DefaultFactory>();
14+
15+
// Log directory — current folder for this example
16+
defaultFactory.Directory(".");
17+
18+
// Default log level is Info
19+
defaultFactory.Level(NServiceBus.Logging.LogLevel.Debug);
20+
21+
var endpointConfiguration = new EndpointConfiguration("Samples.Logging.Default");
22+
#endregion
23+
24+
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
25+
endpointConfiguration.UseTransport<LearningTransport>();
26+
27+
return endpointConfiguration;
28+
})
29+
.Build();
30+
31+
await host.StartAsync();
32+
33+
var endpointInstance = host.Services.GetRequiredService<IMessageSession>();
34+
35+
var myMessage = new MyMessage();
36+
await endpointInstance.SendLocal(myMessage);
37+
38+
Console.WriteLine("Press any key to exit");
39+
Console.ReadKey();
40+
41+
await host.StopAsync();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
<LangVersion>preview</LangVersion>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="NServiceBus" Version="10.0.0-alpha.1" />
9+
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="4.0.0-alpha.1" />
10+
</ItemGroup>
11+
</Project>

samples/logging/default/Core_10/prerelease.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)