Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Log() as a static function?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Log() as a static function?

    Hi, I would be interrested to write to the Log also from code that is not inherited from an Indictor or Strategy or other NinjaScript.
    So I would need a static globally accesisble Log() function.

    Is there something available?

    In NT7 I would use
    NinjaTrader.Cbi.LogEventArgs.ProcessEventArgs(new NinjaTrader.Cbi.LogEventArgs("File not found:" , NinjaTrader.Cbi.LogLevel.Warning));

    In NT8 this has changed and I have NinjaTrader.Cbi.Log.Process( ?????) ,

    but the first arguments, resourcetype , name , args[] are not known to me.

    Can you help with giving a globally (static) accesiblle Log() and Trace() function.?

    Andreas

    #2
    Hello,

    Thank you for the question.

    For the OutputWindow and log there is a static method set which can be found here: http://ninjatrader.com/support/helpG...ightsub=output

    Here are the specific examples:

    Instead of Print(), use Output.Process() to write a message.
    Instead of ClearOutputWindow(), use Output.Reset() to clear the output window.

    Instead of Log(), use Log.Process() to send a message to NinjaTrader logs.

    Code:
    NinjaTrader.Cbi.Log.Process(typeof(Resource), "someName", new object[] { "My log message" }, LogLevel.Error, LogCategories.Default, null)
    The page also shows the namespace needed in case this is not in a inherited script.

    I look forward to being of further assistance.

    Comment


      #3
      Log.Process and threads

      When I call the static Log.Process(... function from a background or worker thread then I get errors related to threading issues.

      Is it safe to call this function from other threads? If not, do you have a remedy ready? Some invoke function ?


      Thank you

      Andreas

      Comment


        #4
        Hello,

        Thank you for the question.

        From a background thread you would likely need to invoke using the dispatcher.

        Could you provide a snippet of the code you are using?

        Depending on the context, you may need to use something similar to the following syntax when using cross thread operations:

        Code:
          this.Dispatcher.BeginInvoke((Action)(() =>
        {
            //print or other gui operation here
        }));
        If the above does not work or continues to produce the error, please provide more details on the code you are using and it would be more apparent which dispatcher you may need to use. This plays a large part in background/gui operations along with Addons accessing multiple windows etc.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, Today, 06:46 AM
        0 responses
        8 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, Yesterday, 05:21 PM
        0 responses
        14 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        15 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        82 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        48 views
        0 likes
        Last Post PaulMohn  
        Working...
        X