masilver
I'm new here

Logging in Templates

I'm trying to log some debug messages in a template using Out.DebugWriteLine.

The problem is I need to use it in a code behind section (<script runat="server">) in the Page_Load method.

I receive this error when using Out:

  CS0103: The name 'Out' does not exist in the current context

So I tried adding <$@ Import Namespace="CrownPeak.CMSAPI" $> right before the script section, but then I receive:

  "The type or namespace name 'CMSAPI' does not exist in the namespace 'CrownPeak' (are you missing an assembly reference?)"

How can I use Out.DebugWriteLine in Page_Load or is there a better logging solution?

...Thanks...

...Michael...

 

0 Kudos
1 Reply
RichardLund
Crownpeak Employee

Hi Michael,

You can't use the Crownpeak utility classes from your ASPX pages. That code runs on your hosting web servers, and the CMSAPI code only runs within DXM.

Depending on your requirements, you could look to use tracing (e.g. https://learn.microsoft.com/en-us/previous-versions/aspnet/bb386420(v=vs.100)) or you could log to a text file within the /App_Data folder.

In general, I would do this before putting the code into Crownpeak in the first place. Once you have fully working, tested code, it is usually simple to have the CMS publish that out and then there's no reason it shouldn't continue to work in your hosting environment.

Regards,
Richard.

0 Kudos