Developer forum

Forum » Feature requests » Monitoring - Template in log content

Monitoring - Template in log content

Mikkel Ulstrup
Reply

Hi,

 

In the monitoring section > Event Viewer > Errors, we can find information about errors on the solution. Somtimes the error happens in the template:

2020-02-10 08:57:38.352: Error executing razor template (Designs/Rapido/Paragraph/some-template.cshtml) https://some-solution.com/. System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_0eec582c5f284b3799b80f73a6586f9a.Execute() in D:\path\some-solution.cloud.dynamicweb-cms.com\Files\Templates\Designs\Rapido\Paragraph\some-template.cshtml:line 15
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()

The problem is that the line umber does not match, as the template only is a part of the entire rendering. When we get this error in the frontend, you print out the entire page in code, so it is possible to find the excat line that caused the error. Can we get this as well in the log content in this monitoring section?

 

Kind regards

Mikkel Ulstrup


Replies

 
Nicolai Pedersen
Reply

Hi Mikkel

I cannot reproduce that -  see dump.

Can you provide a bit of more information?

Thanks, Nicolai

Capture.JPG
 
Nicolai Pedersen
Reply

If you use @Include - the exception is the combined template line I guess... Is that it?

 
Mikkel Ulstrup
Reply

Hi Nicolai,

 

Yes, I guess that it is the include statemets, that is messing up the line numbers. This template has a lot of usings, and it does not have 2066 lines.

2020-01-14 16:05:42.525: Error executing razor template (Designs/Rapido/eCom/Productlist/ProductsRender.cshtml) https://asd.com/Default.aspx?ID=52&Search={{searchParameter}}&GroupID={{groupId}}. System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_61cf3dc6ceba45f78a88232c2a7bb27a.<ProductGroupFilter>b__23_0(TextWriter __razor_helper_writer) in D:\Dynamicweb.net\Solutions\asd.cloud.dynamicweb-cms.com\Files\Templates\Designs\Rapido\eCom\Productlist\ProductsRender.cshtml:line 1926
at CompiledRazorTemplates.Dynamic.RazorEngine_61cf3dc6ceba45f78a88232c2a7bb27a.<>c__DisplayClass2_0.<RenderBlock>b__0(TextWriter __razor_helper_writer) in D:\Dynamicweb.net\Solutions\asd.cloud.dynamicweb-cms.com\Files\Templates\Designs\Rapido\eCom\Productlist\ProductsRender.cshtml:line 173
at CompiledRazorTemplates.Dynamic.RazorEngine_61cf3dc6ceba45f78a88232c2a7bb27a.<>c__DisplayClass1_0.<RenderBlockList>b__0(TextWriter __razor_helper_writer) in D:\Dynamicweb.net\Solutions\asd.cloud.dynamicweb-cms.com\Files\Templates\Designs\Rapido\eCom\Productlist\ProductsRender.cshtml:line 85
at CompiledRazorTemplates.Dynamic.RazorEngine_61cf3dc6ceba45f78a88232c2a7bb27a.Execute() in D:\Dynamicweb.net\Solutions\asd.cloud.dynamicweb-cms.com\Files\Templates\Designs\Rapido\eCom\Productlist\ProductsRender.cshtml:line 2066
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate() 

 

Is it possible to the same "template print" as in the frontend?

 

- Mikkel

 

 
Nicolai Pedersen
Reply

Well - it would be a lot of data to log. And it is possible to find the right line by making an intentional error in the template and then locate the right line.

In Settings, web & http, security there is a new setting to throw a real exception when template errors occur - they might log better information.

 
Mikkel Ulstrup
Reply

Hi Nicolai,

 

We will try the mentioned setting - see if it helps

 

- Mikkel