コード例 #1
0
        protected override void Write(LogEventInfo logEvent)
        {
            if (_client == null)
            {
                _client = ElmahioAPI.Create(ApiKey);
            }

            var title = Layout != null && Layout.ToString() != "'${longdate}|${level:uppercase=true}|${logger}|${message}'"
                ? Layout.Render(logEvent)
                : logEvent.FormattedMessage;

            var message = new CreateMessage
            {
                Title       = title,
                Severity    = LevelToSeverity(logEvent.Level),
                DateTime    = logEvent.TimeStamp.ToUniversalTime(),
                Detail      = logEvent.Exception?.ToString(),
                Data        = PropertiesToData(logEvent.Properties),
                Source      = logEvent.LoggerName,
                Hostname    = MachineName(logEvent),
                Application = Application,
                User        = User(logEvent),
            };

            _client.Messages.CreateAndNotify(new Guid(LogId), message);
        }
コード例 #2
0
ファイル: ErrorLog.cs プロジェクト: VamsiModem/elmah.io
        /// <summary>
        /// The constructor used by ELMAH. ELMAH provides key/value pairs in the config dictionary,
        /// as specified in attributes in the ELMAH XML configuration (web.config).
        /// This constructor intentionally handles the internal ILogger instance as singleton.
        /// ELMAH calls this constructor one time per error logged and to only create the logger
        /// once, letting you listen for events on the logger etc., the logger needs to be
        /// singleton.
        /// </summary>
        public ErrorLog(IDictionary config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            _logId = config.LogId();
            var apiKey = config.ApiKey();

            ApplicationName = config.ApplicationName();

            if (Api != null)
            {
                return;
            }

            var url        = config.Url();
            var elmahioApi = ElmahioAPI.Create(apiKey);

            if (url != null)
            {
                elmahioApi.BaseUri = url;
            }

            Api = elmahioApi;
        }
コード例 #3
0
 public ElmahIoLogger(string apiKey, Guid logId, ElmahIoProviderOptions options)
 {
     _logId      = logId;
     _elmahioApi = new ElmahioAPI(new ApiKeyCredentials(apiKey), HttpClientHandlerFactory.GetHttpClientHandler(options));
     _elmahioApi.Messages.OnMessage     += (sender, args) => options.OnMessage?.Invoke(args.Message);
     _elmahioApi.Messages.OnMessageFail += (sender, args) => options.OnError?.Invoke(args.Message, args.Error);
 }
コード例 #4
0
        void MyApp_UnhandledExceptionHandler(object sender, RaiseThrowableEventArgs e)
        {
            var packageInfo = PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.MetaData);

            // Do your error handling here.

            if (api == null)
            {
                api = ElmahioAPI.Create("API_KEY");
            }

            var exception     = e.Exception;
            var baseException = exception?.GetBaseException();

            api.Messages.Create("LOG_ID", new CreateMessage
            {
                Data        = exception?.ToDataList(),
                DateTime    = DateTime.UtcNow,
                Detail      = exception?.ToString(),
                Severity    = "Error",
                Source      = baseException?.Source,
                Title       = baseException?.Message ?? "Unhandled Xamarin exception",
                Type        = baseException?.GetType().FullName,
                Version     = packageInfo.VersionName,
                Application = packageInfo.PackageName,
            });
        }
コード例 #5
0
 public ElmahIoLogger(string apiKey, Guid logId, ElmahIoProviderOptions options)
 {
     _logId      = logId;
     _elmahioApi = ElmahioAPI.Create(apiKey);
     _elmahioApi.Messages.OnMessage     += (sender, args) => options.OnMessage?.Invoke(args.Message);
     _elmahioApi.Messages.OnMessageFail += (sender, args) => options.OnError?.Invoke(args.Message, args.Error);
     _options = options;
 }
コード例 #6
0
 private void EnsureClient()
 {
     if (Client == null)
     {
         var api = (ElmahioAPI)ElmahioAPI.Create(_apiKey);
         api.HttpClient.Timeout = new TimeSpan(0, 0, 5);
         api.HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(new ProductHeaderValue("Elmah.Io.Log4Net", _assemblyVersion)));
         Client = api;
     }
 }
コード例 #7
0
        public void SetUp()
        {
            loggedMessages = null;
            clientMock     = Substitute.For <IElmahioAPI>();
            var messagesMock = Substitute.For <IMessagesClient>();

            clientMock.Messages.Returns(messagesMock);
            messagesMock
            .When(x => x.CreateBulkAndNotifyAsync(Arg.Any <Guid>(), Arg.Any <IList <CreateMessage> >()))
            .Do(x => loggedMessages = x.Arg <IList <CreateMessage> >());
        }
コード例 #8
0
 public ElmahIoTraceListener(IElmahioAPI client)
 {
     _client = client;
 }
コード例 #9
0
 public ElmahIoTarget(IElmahioAPI client)
 {
     _client = client;
 }
コード例 #10
0
ファイル: ErrorLog.cs プロジェクト: VamsiModem/elmah.io
 /// <summary>
 /// ELMAH doesn't use this constructor and it is only published in order for you to create
 /// a new error logger using a custom implementation of ILogger or an instance of Logger that
 /// you've already created. If you implement your own ILogger, please  identify yourself
 /// using an appropriate user agent.
 /// </summary>
 public ErrorLog(IElmahioAPI logger, Guid logId)
 {
     Api    = logger;
     _logId = logId;
 }
コード例 #11
0
ファイル: ErrorLog.cs プロジェクト: VamsiModem/elmah.io
 public ErrorLog(IElmahioAPI logger)
 {
     Api = logger;
 }
コード例 #12
0
 internal ElmahIoLogger(IElmahioAPI api)
 {
     _elmahioApi = api;
 }