NLog webservice target, slack icon based on log level The Next CEO of Stack OverflowHow to apply different layouts to the same target in NLog?Nlog: send mail when Loglevel >= Loglevel.Error with last x messagesNLog fails to open file on Windows with MonoNLog - set the logger level in runtime?Log to different files with NLog and configure it with NLog Config XMLHow to log a message correlation Id with ServiceStack.Logging ILog?how to disable the particular log, dynamically in Nlog using C#?could not load file or assembly Nlog.web.aspnetcore or one of its dependenciesParameters empty (or not supplied to CommandText) when using NLog with ASP.NET Core and SQLiteNLog dotnet core 2.1 mail ignoring level

TikZ: How to reverse arrow direction without switching start/end point?

Is wanting to ask what to write an indication that you need to change your story?

Rotate a column

Proper way to express "He disappeared them"

How to write a definition with variants?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

What was the first Unix version to run on a microcomputer?

Is micro rebar a better way to reinforce concrete than rebar?

Won the lottery - how do I keep the money?

Domestic-to-international connection at Orlando (MCO)

Axiom Schema vs Axiom

Is there a difference between "Fahrstuhl" and "Aufzug"

Flying from Cape Town to England and return to another province

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Find non-case sensitive string in a mixed list of elements?

Is the D&D universe the same as the Forgotten Realms universe?

Why didn't Khan get resurrected in the Genesis Explosion?

How is this set of matrices closed under multiplication?

How to edit “Name” property in GCI output?

Why the difference in type-inference over the as-pattern in two similar function definitions?

Can this equation be simplified further?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?



NLog webservice target, slack icon based on log level



The Next CEO of Stack OverflowHow to apply different layouts to the same target in NLog?Nlog: send mail when Loglevel >= Loglevel.Error with last x messagesNLog fails to open file on Windows with MonoNLog - set the logger level in runtime?Log to different files with NLog and configure it with NLog Config XMLHow to log a message correlation Id with ServiceStack.Logging ILog?how to disable the particular log, dynamically in Nlog using C#?could not load file or assembly Nlog.web.aspnetcore or one of its dependenciesParameters empty (or not supplied to CommandText) when using NLog with ASP.NET Core and SQLiteNLog dotnet core 2.1 mail ignoring level










1















I'm new to NLog, and fighting with finding the solution to what I'm going for.



I'd like warning and up to get pushed to a slack channel with log level specific icons. I have got that working, technically. I have 2 pairs of targets/loggers that are hard coded to catch warnings only, and errors and above, and have 'warning' or 'error' icons hard coded into the layout template.



<target xsi:type="WebService"
name="slackWarningTarget"
url="https://hooks.slack.com/services/xx/xx/xx"
protocol="JsonPost"
encoding="utf-8"
>

<parameter name="text" type="System.String" layout=":warning: $machinename $message"/>
<parameter name="channel" type="System.String" layout="xx"/>
</target>


and



<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="slackWarningTarget">


Is there a way to better accomplish this? I want warning level to map to :warning:, etc.



I'd also like some info level stuff pushed there as well. To do this I created a named logger that always logs to the slack channel, but it results in duplicated messages if they are warning or above.



<logger name="noticeLogger" writeTo="slackInfoTarget" />


I'd guess there is a much more elegant way to do both of these things than i have come up with on my own.










share|improve this question




























    1















    I'm new to NLog, and fighting with finding the solution to what I'm going for.



    I'd like warning and up to get pushed to a slack channel with log level specific icons. I have got that working, technically. I have 2 pairs of targets/loggers that are hard coded to catch warnings only, and errors and above, and have 'warning' or 'error' icons hard coded into the layout template.



    <target xsi:type="WebService"
    name="slackWarningTarget"
    url="https://hooks.slack.com/services/xx/xx/xx"
    protocol="JsonPost"
    encoding="utf-8"
    >

    <parameter name="text" type="System.String" layout=":warning: $machinename $message"/>
    <parameter name="channel" type="System.String" layout="xx"/>
    </target>


    and



    <logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="slackWarningTarget">


    Is there a way to better accomplish this? I want warning level to map to :warning:, etc.



    I'd also like some info level stuff pushed there as well. To do this I created a named logger that always logs to the slack channel, but it results in duplicated messages if they are warning or above.



    <logger name="noticeLogger" writeTo="slackInfoTarget" />


    I'd guess there is a much more elegant way to do both of these things than i have come up with on my own.










    share|improve this question


























      1












      1








      1








      I'm new to NLog, and fighting with finding the solution to what I'm going for.



      I'd like warning and up to get pushed to a slack channel with log level specific icons. I have got that working, technically. I have 2 pairs of targets/loggers that are hard coded to catch warnings only, and errors and above, and have 'warning' or 'error' icons hard coded into the layout template.



      <target xsi:type="WebService"
      name="slackWarningTarget"
      url="https://hooks.slack.com/services/xx/xx/xx"
      protocol="JsonPost"
      encoding="utf-8"
      >

      <parameter name="text" type="System.String" layout=":warning: $machinename $message"/>
      <parameter name="channel" type="System.String" layout="xx"/>
      </target>


      and



      <logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="slackWarningTarget">


      Is there a way to better accomplish this? I want warning level to map to :warning:, etc.



      I'd also like some info level stuff pushed there as well. To do this I created a named logger that always logs to the slack channel, but it results in duplicated messages if they are warning or above.



      <logger name="noticeLogger" writeTo="slackInfoTarget" />


      I'd guess there is a much more elegant way to do both of these things than i have come up with on my own.










      share|improve this question
















      I'm new to NLog, and fighting with finding the solution to what I'm going for.



      I'd like warning and up to get pushed to a slack channel with log level specific icons. I have got that working, technically. I have 2 pairs of targets/loggers that are hard coded to catch warnings only, and errors and above, and have 'warning' or 'error' icons hard coded into the layout template.



      <target xsi:type="WebService"
      name="slackWarningTarget"
      url="https://hooks.slack.com/services/xx/xx/xx"
      protocol="JsonPost"
      encoding="utf-8"
      >

      <parameter name="text" type="System.String" layout=":warning: $machinename $message"/>
      <parameter name="channel" type="System.String" layout="xx"/>
      </target>


      and



      <logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="slackWarningTarget">


      Is there a way to better accomplish this? I want warning level to map to :warning:, etc.



      I'd also like some info level stuff pushed there as well. To do this I created a named logger that always logs to the slack channel, but it results in duplicated messages if they are warning or above.



      <logger name="noticeLogger" writeTo="slackInfoTarget" />


      I'd guess there is a much more elegant way to do both of these things than i have come up with on my own.







      nlog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 18:43









      Julian

      12.7k75592




      12.7k75592










      asked Mar 21 at 17:56









      ChrisChris

      187112




      187112






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You could do that from config with a $when, e.g.



          layout="$when:when=$level=='Warn':inner=:warning::else:$when:when=$level== 'Error':inner=:error::else:todo"


          but it get clumsy fast.



          Another option is to register a custom layout renderer:



          // register in the start of your program (e.g. main, app_start)
          // usage $slackIcon
          LayoutRenderer.Register("slackIcon", logEvent =>

          if (logEvent.Level == LogLevel.Warn)

          return ":warning:";

          if (logEvent.Level == LogLevel.Error)

          return ":error:";


          return ":other:";
          //etc
          );


          See How to write a custom layout renderer






          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%2f55286534%2fnlog-webservice-target-slack-icon-based-on-log-level%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You could do that from config with a $when, e.g.



            layout="$when:when=$level=='Warn':inner=:warning::else:$when:when=$level== 'Error':inner=:error::else:todo"


            but it get clumsy fast.



            Another option is to register a custom layout renderer:



            // register in the start of your program (e.g. main, app_start)
            // usage $slackIcon
            LayoutRenderer.Register("slackIcon", logEvent =>

            if (logEvent.Level == LogLevel.Warn)

            return ":warning:";

            if (logEvent.Level == LogLevel.Error)

            return ":error:";


            return ":other:";
            //etc
            );


            See How to write a custom layout renderer






            share|improve this answer



























              0














              You could do that from config with a $when, e.g.



              layout="$when:when=$level=='Warn':inner=:warning::else:$when:when=$level== 'Error':inner=:error::else:todo"


              but it get clumsy fast.



              Another option is to register a custom layout renderer:



              // register in the start of your program (e.g. main, app_start)
              // usage $slackIcon
              LayoutRenderer.Register("slackIcon", logEvent =>

              if (logEvent.Level == LogLevel.Warn)

              return ":warning:";

              if (logEvent.Level == LogLevel.Error)

              return ":error:";


              return ":other:";
              //etc
              );


              See How to write a custom layout renderer






              share|improve this answer

























                0












                0








                0







                You could do that from config with a $when, e.g.



                layout="$when:when=$level=='Warn':inner=:warning::else:$when:when=$level== 'Error':inner=:error::else:todo"


                but it get clumsy fast.



                Another option is to register a custom layout renderer:



                // register in the start of your program (e.g. main, app_start)
                // usage $slackIcon
                LayoutRenderer.Register("slackIcon", logEvent =>

                if (logEvent.Level == LogLevel.Warn)

                return ":warning:";

                if (logEvent.Level == LogLevel.Error)

                return ":error:";


                return ":other:";
                //etc
                );


                See How to write a custom layout renderer






                share|improve this answer













                You could do that from config with a $when, e.g.



                layout="$when:when=$level=='Warn':inner=:warning::else:$when:when=$level== 'Error':inner=:error::else:todo"


                but it get clumsy fast.



                Another option is to register a custom layout renderer:



                // register in the start of your program (e.g. main, app_start)
                // usage $slackIcon
                LayoutRenderer.Register("slackIcon", logEvent =>

                if (logEvent.Level == LogLevel.Warn)

                return ":warning:";

                if (logEvent.Level == LogLevel.Error)

                return ":error:";


                return ":other:";
                //etc
                );


                See How to write a custom layout renderer







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 21 at 18:43









                JulianJulian

                12.7k75592




                12.7k75592





























                    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%2f55286534%2fnlog-webservice-target-slack-icon-based-on-log-level%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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현