How do I add cross-cutting information to Microsoft.Extensions.Logging events?
up vote
0
down vote
favorite
I'm trying to set up a basic prototype of client-server applications, both using ASP.NET Core 2.0. As part of this, I'm sending diagnostic information to Seq. In the Startup class for each application, I'm using Seq.Extensions.Logging and configuring the Seq sinks as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(builder =>
{
builder
.SetMinimumLevel(LogLevel.Debug)
.AddSeq();
});
This works; all the events appear in Seq. However, it's not possible to easily distinguish which application any specific event is from.
In the past, using Serilog, I have been able to add propertes to the logger which are included in every event. Typically I would add the name of the application and the host it is running on as a pair of additional properties:
Log.Logger = new LoggerConfiguration()
.Enrich.WithMachineName()
// ...other configuration...
.CreateLogger();
Is there a way to configure the Microsoft logging extensions to do the same thing?
c# logging asp.net-core-2.0 seq
add a comment |
up vote
0
down vote
favorite
I'm trying to set up a basic prototype of client-server applications, both using ASP.NET Core 2.0. As part of this, I'm sending diagnostic information to Seq. In the Startup class for each application, I'm using Seq.Extensions.Logging and configuring the Seq sinks as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(builder =>
{
builder
.SetMinimumLevel(LogLevel.Debug)
.AddSeq();
});
This works; all the events appear in Seq. However, it's not possible to easily distinguish which application any specific event is from.
In the past, using Serilog, I have been able to add propertes to the logger which are included in every event. Typically I would add the name of the application and the host it is running on as a pair of additional properties:
Log.Logger = new LoggerConfiguration()
.Enrich.WithMachineName()
// ...other configuration...
.CreateLogger();
Is there a way to configure the Microsoft logging extensions to do the same thing?
c# logging asp.net-core-2.0 seq
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to set up a basic prototype of client-server applications, both using ASP.NET Core 2.0. As part of this, I'm sending diagnostic information to Seq. In the Startup class for each application, I'm using Seq.Extensions.Logging and configuring the Seq sinks as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(builder =>
{
builder
.SetMinimumLevel(LogLevel.Debug)
.AddSeq();
});
This works; all the events appear in Seq. However, it's not possible to easily distinguish which application any specific event is from.
In the past, using Serilog, I have been able to add propertes to the logger which are included in every event. Typically I would add the name of the application and the host it is running on as a pair of additional properties:
Log.Logger = new LoggerConfiguration()
.Enrich.WithMachineName()
// ...other configuration...
.CreateLogger();
Is there a way to configure the Microsoft logging extensions to do the same thing?
c# logging asp.net-core-2.0 seq
I'm trying to set up a basic prototype of client-server applications, both using ASP.NET Core 2.0. As part of this, I'm sending diagnostic information to Seq. In the Startup class for each application, I'm using Seq.Extensions.Logging and configuring the Seq sinks as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(builder =>
{
builder
.SetMinimumLevel(LogLevel.Debug)
.AddSeq();
});
This works; all the events appear in Seq. However, it's not possible to easily distinguish which application any specific event is from.
In the past, using Serilog, I have been able to add propertes to the logger which are included in every event. Typically I would add the name of the application and the host it is running on as a pair of additional properties:
Log.Logger = new LoggerConfiguration()
.Enrich.WithMachineName()
// ...other configuration...
.CreateLogger();
Is there a way to configure the Microsoft logging extensions to do the same thing?
c# logging asp.net-core-2.0 seq
c# logging asp.net-core-2.0 seq
asked yesterday
Paul Turner
24.8k1179139
24.8k1179139
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
There are two options for you.
Use built-in
Seqfeature.
For
Seq, it provides API Keys which is used to identity the client application. You could add theApplied propertieswith the specific name like your project name, and configure the api key by
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
});
Or
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("http://xxx:5341", apiKey: "K5HzACIfiQxr67CKlvUj");
});
Use
Serialogto configure the output template like
var output = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {ActionName} {UserName} {NewLine}{Exception} {MachineName}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Populates a 'User' property on every log entry
.Enrich.WithProperty("MachineName", Environment.MachineName) //new field
.WriteTo.RollingFile("Logs/app-{Date}.txt", outputTemplate: output)
.WriteTo.Seq("http://xxx:5341",apiKey: "K5HzACIfiQxr67CKlvUj")
.CreateLogger();
loggerFactory
//.AddFile("Logs/app-{Date}.txt")
.AddSerilog();
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
There are two options for you.
Use built-in
Seqfeature.
For
Seq, it provides API Keys which is used to identity the client application. You could add theApplied propertieswith the specific name like your project name, and configure the api key by
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
});
Or
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("http://xxx:5341", apiKey: "K5HzACIfiQxr67CKlvUj");
});
Use
Serialogto configure the output template like
var output = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {ActionName} {UserName} {NewLine}{Exception} {MachineName}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Populates a 'User' property on every log entry
.Enrich.WithProperty("MachineName", Environment.MachineName) //new field
.WriteTo.RollingFile("Logs/app-{Date}.txt", outputTemplate: output)
.WriteTo.Seq("http://xxx:5341",apiKey: "K5HzACIfiQxr67CKlvUj")
.CreateLogger();
loggerFactory
//.AddFile("Logs/app-{Date}.txt")
.AddSerilog();
add a comment |
up vote
0
down vote
There are two options for you.
Use built-in
Seqfeature.
For
Seq, it provides API Keys which is used to identity the client application. You could add theApplied propertieswith the specific name like your project name, and configure the api key by
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
});
Or
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("http://xxx:5341", apiKey: "K5HzACIfiQxr67CKlvUj");
});
Use
Serialogto configure the output template like
var output = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {ActionName} {UserName} {NewLine}{Exception} {MachineName}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Populates a 'User' property on every log entry
.Enrich.WithProperty("MachineName", Environment.MachineName) //new field
.WriteTo.RollingFile("Logs/app-{Date}.txt", outputTemplate: output)
.WriteTo.Seq("http://xxx:5341",apiKey: "K5HzACIfiQxr67CKlvUj")
.CreateLogger();
loggerFactory
//.AddFile("Logs/app-{Date}.txt")
.AddSerilog();
add a comment |
up vote
0
down vote
up vote
0
down vote
There are two options for you.
Use built-in
Seqfeature.
For
Seq, it provides API Keys which is used to identity the client application. You could add theApplied propertieswith the specific name like your project name, and configure the api key by
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
});
Or
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("http://xxx:5341", apiKey: "K5HzACIfiQxr67CKlvUj");
});
Use
Serialogto configure the output template like
var output = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {ActionName} {UserName} {NewLine}{Exception} {MachineName}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Populates a 'User' property on every log entry
.Enrich.WithProperty("MachineName", Environment.MachineName) //new field
.WriteTo.RollingFile("Logs/app-{Date}.txt", outputTemplate: output)
.WriteTo.Seq("http://xxx:5341",apiKey: "K5HzACIfiQxr67CKlvUj")
.CreateLogger();
loggerFactory
//.AddFile("Logs/app-{Date}.txt")
.AddSerilog();
There are two options for you.
Use built-in
Seqfeature.
For
Seq, it provides API Keys which is used to identity the client application. You could add theApplied propertieswith the specific name like your project name, and configure the api key by
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq(Configuration.GetSection("Seq"));
});
Or
services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSeq("http://xxx:5341", apiKey: "K5HzACIfiQxr67CKlvUj");
});
Use
Serialogto configure the output template like
var output = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message} {ActionName} {UserName} {NewLine}{Exception} {MachineName}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext() // Populates a 'User' property on every log entry
.Enrich.WithProperty("MachineName", Environment.MachineName) //new field
.WriteTo.RollingFile("Logs/app-{Date}.txt", outputTemplate: output)
.WriteTo.Seq("http://xxx:5341",apiKey: "K5HzACIfiQxr67CKlvUj")
.CreateLogger();
loggerFactory
//.AddFile("Logs/app-{Date}.txt")
.AddSerilog();
answered 23 hours ago
Tao Zhou
3,77721026
3,77721026
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409133%2fhow-do-i-add-cross-cutting-information-to-microsoft-extensions-logging-events%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown