textPayload: "Successfully sent to Google Cloud Logging API"
<configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="CloudLogger" type="Google.Cloud.Logging.Log4Net.GoogleStackdriverAppender,Google.Cloud.Logging.Log4Net"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message" /> </layout> <projectId value="YOUR-PROJECT-ID" /> <logId value="mySampleLog" /> </appender> <root> <level value="ALL" /> <appender-ref ref="CloudLogger" /> </root> </log4net>
log4net.Config.XmlConfigurator.Configure();
protected void Application_Start(){ GlobalConfiguration.Configure(WebApiConfig.Register); // Configure log4net to use Stackdriver logging from the XML configuration file. log4net.Config.XmlConfigurator.Configure();}
using log4net;
// Retrieve a logger for this context.ILog log = LogManager.GetLogger(typeof(WebApiConfig));// Log some information to Google Stackdriver Logging.log.Info("Hello World.");
using Google.Cloud.Diagnostics.AspNet;
public static void Register(HttpConfiguration config){ // Add a catch all for the uncaught exceptions. string projectId = "YOUR-PROJECT-ID"; string serviceName = "NAME-OF-YOUR-SERVICE"; string version = "VERSION-OF-YOUR-SERVICE"; // Add a catch all for the uncaught exceptions. config.Services.Add(typeof(IExceptionLogger), ErrorReportingExceptionLogger.Create(projectId, serviceName, version));}
Use promo code NEXT1720 to save $300 off general admission
No comments :
Post a Comment