Asp.Net Web Api LoggingCorrect way to use Serilog with WebApi2WCF vs ASP.NET Web APIServiceStack vs ASP.Net Web APIHow do I get ASP.NET Web API to return JSON instead of XML using Chrome?Pass an array of integers to ASP.NET Web API?How to secure an ASP.NET Web APIBest practice to call ConfigureAwait for all server-side codeHow do we determine whether we are using Web API 1 or Web API 2?ASP.NET Core 1.0 loggingLogging ASP.NET Core on Azure via SerilogSerilog - Logging to separate instances for API vs Web App
Are the plates of a battery really charged?
Did Winston Churchill praise Rolls-Royce engines?
How did sloshing prevent the Apollo Service Module from moving safely away from the Command Module and how was this fixed?
How come having a Deathly Hallow is not a big deal?
C++20 with u8, char8_t and std::string
"Best practices" for formulating MIPs
What does "another" mean in this case?
Does a reference have a storage location?
Term for a character that only exists to be talked to
Why is 一日 used instead of 日 to ask how your day is?
Birthday girl's casino game
What is a "tittering order"?
Should I cheat if the majority does it?
Sleepy tired vs physically tired
Who pays for increased security measures on flights to the US?
How might boat designs change in order to allow them to be pulled by dragons?
Go function to test whether a file exists
What is the difference between a historical drama and a period drama?
Show that there are infinitely more problems than we will ever be able to compute
Blood-based alcohol for vampires?
Has there ever been a cold war other than between the U.S. and the U.S.S.R.?
How to widen the page
What could a Medieval society do with excess animal blood?
Old story where computer expert digitally animates The Lord of the Rings
Asp.Net Web Api Logging
Correct way to use Serilog with WebApi2WCF vs ASP.NET Web APIServiceStack vs ASP.Net Web APIHow do I get ASP.NET Web API to return JSON instead of XML using Chrome?Pass an array of integers to ASP.NET Web API?How to secure an ASP.NET Web APIBest practice to call ConfigureAwait for all server-side codeHow do we determine whether we are using Web API 1 or Web API 2?ASP.NET Core 1.0 loggingLogging ASP.NET Core on Azure via SerilogSerilog - Logging to separate instances for API vs Web App
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to setup logging on my asp.net web api (Not Asp.Net Core), and want to make sure that I follow best practices (as close as possible). I am using SeriLog in my services, and would like to use this product for my Web Api as well. I am not sure of the best way to setup logging in Web API, and I would like to set it up such that depending on the context (my api serves multiple apps) I would like to be able to log to a separate Microsoft Sql Server. Can somebody please provide some direction on how to get started at this task, potential pitfalls, or a link to an article that I have yet to find on how to set this up in Asp.Net?
asp.net-web-api serilog
add a comment |
I want to setup logging on my asp.net web api (Not Asp.Net Core), and want to make sure that I follow best practices (as close as possible). I am using SeriLog in my services, and would like to use this product for my Web Api as well. I am not sure of the best way to setup logging in Web API, and I would like to set it up such that depending on the context (my api serves multiple apps) I would like to be able to log to a separate Microsoft Sql Server. Can somebody please provide some direction on how to get started at this task, potential pitfalls, or a link to an article that I have yet to find on how to set this up in Asp.Net?
asp.net-web-api serilog
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47
add a comment |
I want to setup logging on my asp.net web api (Not Asp.Net Core), and want to make sure that I follow best practices (as close as possible). I am using SeriLog in my services, and would like to use this product for my Web Api as well. I am not sure of the best way to setup logging in Web API, and I would like to set it up such that depending on the context (my api serves multiple apps) I would like to be able to log to a separate Microsoft Sql Server. Can somebody please provide some direction on how to get started at this task, potential pitfalls, or a link to an article that I have yet to find on how to set this up in Asp.Net?
asp.net-web-api serilog
I want to setup logging on my asp.net web api (Not Asp.Net Core), and want to make sure that I follow best practices (as close as possible). I am using SeriLog in my services, and would like to use this product for my Web Api as well. I am not sure of the best way to setup logging in Web API, and I would like to set it up such that depending on the context (my api serves multiple apps) I would like to be able to log to a separate Microsoft Sql Server. Can somebody please provide some direction on how to get started at this task, potential pitfalls, or a link to an article that I have yet to find on how to set this up in Asp.Net?
asp.net-web-api serilog
asp.net-web-api serilog
edited Mar 25 at 18:45
dmoore1181
asked Mar 25 at 17:47
dmoore1181dmoore1181
4356 silver badges21 bronze badges
4356 silver badges21 bronze badges
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47
add a comment |
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47
add a comment |
2 Answers
2
active
oldest
votes
You can create a centralized logger project and add serilog packages to this project only, and reference this project where you need to use serilog (your services).
And configure serilog using Serilog.Settings.AppSettings package so each service project will read its own configuration (Ex: separate Microsoft SQL Server) from <appSettings>
section in service web.config
useing the ReadFrom.AppSettings()
extension method on your LoggerConfiguration
Sample Logger Class
public static class Logger
private static readonly ILogger _dbLogger;
static Logger()
_dbLogger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
public static void Log(string error)
_dbLogger.Error(error);
Sample appSettings
configuration
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
add a comment |
There is a library from Serilog (MSSQL-Server)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55343754%2fasp-net-web-api-logging%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a centralized logger project and add serilog packages to this project only, and reference this project where you need to use serilog (your services).
And configure serilog using Serilog.Settings.AppSettings package so each service project will read its own configuration (Ex: separate Microsoft SQL Server) from <appSettings>
section in service web.config
useing the ReadFrom.AppSettings()
extension method on your LoggerConfiguration
Sample Logger Class
public static class Logger
private static readonly ILogger _dbLogger;
static Logger()
_dbLogger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
public static void Log(string error)
_dbLogger.Error(error);
Sample appSettings
configuration
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
add a comment |
You can create a centralized logger project and add serilog packages to this project only, and reference this project where you need to use serilog (your services).
And configure serilog using Serilog.Settings.AppSettings package so each service project will read its own configuration (Ex: separate Microsoft SQL Server) from <appSettings>
section in service web.config
useing the ReadFrom.AppSettings()
extension method on your LoggerConfiguration
Sample Logger Class
public static class Logger
private static readonly ILogger _dbLogger;
static Logger()
_dbLogger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
public static void Log(string error)
_dbLogger.Error(error);
Sample appSettings
configuration
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
add a comment |
You can create a centralized logger project and add serilog packages to this project only, and reference this project where you need to use serilog (your services).
And configure serilog using Serilog.Settings.AppSettings package so each service project will read its own configuration (Ex: separate Microsoft SQL Server) from <appSettings>
section in service web.config
useing the ReadFrom.AppSettings()
extension method on your LoggerConfiguration
Sample Logger Class
public static class Logger
private static readonly ILogger _dbLogger;
static Logger()
_dbLogger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
public static void Log(string error)
_dbLogger.Error(error);
Sample appSettings
configuration
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
You can create a centralized logger project and add serilog packages to this project only, and reference this project where you need to use serilog (your services).
And configure serilog using Serilog.Settings.AppSettings package so each service project will read its own configuration (Ex: separate Microsoft SQL Server) from <appSettings>
section in service web.config
useing the ReadFrom.AppSettings()
extension method on your LoggerConfiguration
Sample Logger Class
public static class Logger
private static readonly ILogger _dbLogger;
static Logger()
_dbLogger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
public static void Log(string error)
_dbLogger.Error(error);
Sample appSettings
configuration
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
answered Mar 25 at 21:03
ElasticCodeElasticCode
3,2152 gold badges11 silver badges25 bronze badges
3,2152 gold badges11 silver badges25 bronze badges
add a comment |
add a comment |
There is a library from Serilog (MSSQL-Server)
add a comment |
There is a library from Serilog (MSSQL-Server)
add a comment |
There is a library from Serilog (MSSQL-Server)
There is a library from Serilog (MSSQL-Server)
answered Mar 25 at 18:48
souleater857souleater857
11 bronze badge
11 bronze badge
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55343754%2fasp-net-web-api-logging%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
@PeterBons Sorry for the confusion, but I'm not using .net core.
– dmoore1181
Mar 25 at 18:45
Hi, I have added a rather detailed version of the config we have been using for our Web APIs in my previous job from 2015-ish to 2018 . It might be useful to you : stackoverflow.com/a/55365917/474763
– tsimbalar
Mar 26 at 20:47