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;








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?










share|improve this question
























  • @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

















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?










share|improve this question
























  • @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













0












0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • @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












2 Answers
2






active

oldest

votes


















0














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"/>





share|improve this answer






























    0














    There is a library from Serilog (MSSQL-Server)






    share|improve this answer

























      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
      );



      );













      draft saved

      draft discarded


















      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









      0














      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"/>





      share|improve this answer



























        0














        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"/>





        share|improve this answer

























          0












          0








          0







          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"/>





          share|improve this answer













          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"/>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 21:03









          ElasticCodeElasticCode

          3,2152 gold badges11 silver badges25 bronze badges




          3,2152 gold badges11 silver badges25 bronze badges























              0














              There is a library from Serilog (MSSQL-Server)






              share|improve this answer



























                0














                There is a library from Serilog (MSSQL-Server)






                share|improve this answer

























                  0












                  0








                  0







                  There is a library from Serilog (MSSQL-Server)






                  share|improve this answer













                  There is a library from Serilog (MSSQL-Server)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 18:48









                  souleater857souleater857

                  11 bronze badge




                  11 bronze badge



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript