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

                    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