Skip to content

Commit 15df23d

Browse files
committed
Add log4net messages
1 parent ed61a4e commit 15df23d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+311
-178
lines changed

EPAM.MyBlog.DAL.DB/DAL.cs

Lines changed: 188 additions & 152 deletions
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

EPAM.MyBlog.UI.Web/Controllers/AccountController.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EPAM.MyBlog.UI.Web.Models;
2+
using log4net;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -8,9 +9,14 @@
89

910
namespace EPAM.MyBlog.UI.Web.Controllers
1011
{
12+
13+
1114
[Authorize(Roles = "User")]
1215
public class AccountController : Controller
1316
{
17+
18+
private static ILog logger = LogManager.GetLogger(typeof(AccountController));
19+
1420
//
1521
// GET: /Account/
1622
[AllowAnonymous]
@@ -114,6 +120,8 @@ public ActionResult LogOut(ConfirmModel model)
114120
if (model.Confirm)
115121
{
116122
LoginModel.LogOut();
123+
logger.Info("Пользователь вышел из системы: " + User.Identity.Name);
124+
117125
}
118126
return RedirectToAction("Index", "Home");
119127
}
@@ -159,6 +167,7 @@ public ActionResult DeleteAc(ConfirmModel model)
159167
LoginModel.LogOut();
160168
LoginModel.SaveReason(model.Reason);
161169
LoginModel.DeleteUser(User.Identity.Name);
170+
logger.Info("Пользователь удалил свой аккаунт с логином: " + User.Identity.Name);
162171
}
163172
return RedirectToAction("Index", "Home");
164173
}
@@ -211,15 +220,18 @@ public ActionResult EditSex(UserAboutModel model)
211220
{
212221
if (model.SetSex())
213222
{
223+
logger.Info("Пользователь: " + User.Identity.Name + " изменил информацию о поле");
214224
return RedirectToAction("AboutMe", "Account");
215225
}
216226
else
217227
{
228+
logger.Error("Ошибка при изменении информации о поле пользователя: " + User.Identity.Name);
218229
return View(model);
219230
}
220231
}
221232
else
222233
{
234+
logger.Debug("Невалидная модель при изменении данных о поле пользователя: " + User.Identity.Name);
223235
return View(model);
224236
}
225237
}
@@ -242,15 +254,18 @@ public ActionResult EditDate(UserAboutModel model)
242254
{
243255
if (model.SetDate())
244256
{
257+
logger.Info("Пользователь: " + User.Identity.Name + " изменил дату рождения");
245258
return RedirectToAction("AboutMe", "Account");
246259
}
247260
else
248261
{
262+
logger.Error("Ошибка при изменении даты рождения пользователя: " + User.Identity.Name);
249263
return View(model);
250264
}
251265
}
252266
else
253267
{
268+
logger.Debug("Невалидная модель при изменении даты рождения пользователе: " + User.Identity.Name);
254269
return View(model);
255270
}
256271
}
@@ -275,15 +290,18 @@ public ActionResult EditName(UserAboutModel model)
275290
{
276291
if (model.SetName())
277292
{
293+
logger.Info("Пользователь: " + User.Identity.Name + " изменил имя");
278294
return RedirectToAction("AboutMe", "Account");
279295
}
280296
else
281297
{
298+
logger.Error("Ошибка при изменении имени пользователя: " + User.Identity.Name);
282299
return View(model);
283300
}
284301
}
285302
else
286303
{
304+
logger.Debug("Невалидная модель при изменении имени пользователя: " + User.Identity.Name);
287305
return View(model);
288306
}
289307
}
@@ -309,15 +327,18 @@ public ActionResult EditAbout(UserAboutModel model)
309327
{
310328
if (model.SetAbout())
311329
{
330+
logger.Info("Пользователь: " + User.Identity.Name + " изменил информцияю о себе");
312331
return RedirectToAction("AboutMe", "Account");
313332
}
314333
else
315334
{
335+
logger.Error("Ошибка при изменении информации о себе пользователя: " + User.Identity.Name);
316336
return View(model);
317337
}
318338
}
319339
else
320340
{
341+
logger.Debug("Невалидная модель при изменении информации о себе пользователя: " + User.Identity.Name);
321342
return View(model);
322343
}
323344
}

EPAM.MyBlog.UI.Web/Controllers/AdminController.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EPAM.MyBlog.UI.Web.Models;
2+
using log4net;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -9,6 +10,7 @@ namespace EPAM.MyBlog.UI.Web.Controllers
910
{
1011
public class AdminController : Controller
1112
{
13+
private static ILog logger = LogManager.GetLogger(typeof(AdminController));
1214
//
1315
// GET: /Admin/
1416

@@ -60,15 +62,19 @@ public ActionResult Users(string action)
6062
{
6163
case "addUser":
6264
UserAdminModel.AddUser(names);
65+
logger.Info("Изменены роли на -Пользователь- у пользователей: " + string.Join(",", names.ToArray()));
6366
break;
6467
case "addModer":
6568
UserAdminModel.AddModer(names);
69+
logger.Info("Изменены роли на -Модератор- у пользователей: " + string.Join(",", names.ToArray()));
6670
break;
6771
case "addAdmin":
6872
UserAdminModel.AddAdmin(names);
73+
logger.Info("Изменены роли на -Администратор- у пользователей: " + string.Join(",", names.ToArray()));
6974
break;
7075
case "Delete":
7176
UserAdminModel.DeleteUsers(names);
77+
logger.Info("Удалены учетные записи пользователей: " + string.Join(",", names.ToArray()));
7278
break;
7379
default:
7480
break;
@@ -120,6 +126,7 @@ public ActionResult DeletePost(Guid id, ConfirmModel model, string ReturnUrl)
120126
{
121127
if (PostModel.Delete(id))
122128
{
129+
logger.Info("Удаление поста " + id);
123130
if (!string.IsNullOrWhiteSpace(ReturnUrl))
124131
return Redirect(ReturnUrl);
125132
else
@@ -129,10 +136,15 @@ public ActionResult DeletePost(Guid id, ConfirmModel model, string ReturnUrl)
129136
}
130137
else
131138
{
139+
logger.Error("Ошибка удаления поста " + id);
132140
return View();
133141
}
134142
}
135-
return View();
143+
else
144+
{
145+
logger.Debug("Невалидная модель удаления поста " + id);
146+
return View();
147+
}
136148
}
137149

138150
/// <summary>
@@ -159,6 +171,7 @@ public ActionResult DeleteComment(Guid id, ConfirmModel model, string ReturnUrl)
159171
{
160172
if (CommentModel.Delete(id))
161173
{
174+
logger.Info("Удаление комментария " + id);
162175
if (!string.IsNullOrWhiteSpace(ReturnUrl))
163176
return Redirect(ReturnUrl);
164177
else
@@ -168,6 +181,7 @@ public ActionResult DeleteComment(Guid id, ConfirmModel model, string ReturnUrl)
168181
}
169182
else
170183
{
184+
logger.Error("Ошибка удаления комментария " + id);
171185
return View();
172186
}
173187
}
@@ -191,7 +205,7 @@ public ActionResult Create(RegModel model, string ReturnUrl)
191205
string Result;
192206
if (model.RegByAdmin(out Result))
193207
{
194-
208+
logger.Info("Регистрация Администратором пользователя с логином: " + model.Name);
195209
if (!string.IsNullOrWhiteSpace(ReturnUrl))
196210
{
197211
return Redirect(ReturnUrl);
@@ -203,6 +217,7 @@ public ActionResult Create(RegModel model, string ReturnUrl)
203217
}
204218
else
205219
{
220+
logger.Error("Ошибка регистрации Администратором пользователя с логином: " + model.Name);
206221
ViewData["Result"] = Result;
207222
}
208223
}

EPAM.MyBlog.UI.Web/Controllers/CommentController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EPAM.MyBlog.UI.Web.Models;
2+
using log4net;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -9,6 +10,7 @@ namespace EPAM.MyBlog.UI.Web.Controllers
910
{
1011
public class CommentController : Controller
1112
{
13+
private static ILog logger = LogManager.GetLogger(typeof(CommentController));
1214
//
1315
// GET: /Comment/
1416

@@ -34,10 +36,12 @@ public ActionResult AddComment(CommentModel comment)
3436
CommentModel.Comments.Add(comment);
3537
ViewData["List"] = CommentModel.Comments;
3638
ModelState.Clear();
39+
logger.Info("Добавлен комментарий пользователя: " + comment.Author + " к посту: " + comment.Post_ID);
3740
return RedirectToAction("Posts", "Post", new { Id = comment.Post_ID });
3841
}
3942
else
4043
{
44+
logger.Error("ошибка добавления комментария пользователя: " + comment.Author + " к посту: " + comment.Post_ID);
4145
ViewData["List"] = CommentModel.Comments;
4246
return RedirectToAction("Posts", "Post", new { Id = comment.Post_ID });
4347
}

EPAM.MyBlog.UI.Web/Controllers/FilesController.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EPAM.MyBlog.UI.Web.Models;
2+
using log4net;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -9,6 +10,8 @@ namespace EPAM.MyBlog.UI.Web.Controllers
910
{
1011
public class FilesController : Controller
1112
{
13+
14+
private static ILog logger = LogManager.GetLogger(typeof(FilesController));
1215
//
1316
// GET: /Files/
1417

@@ -28,20 +31,38 @@ public ActionResult EditInfoAvatar(HttpPostedFileBase File)
2831
{
2932
var model = new AvatarModel();
3033
model.Login = User.Identity.Name;
31-
32-
if (ModelState.IsValid)
34+
35+
if (File != null)
3336
{
34-
if (File != null)
37+
if (!File.ContentType.Contains("image"))
38+
{
39+
logger.Error("Попытка загрузки не image в качетсве аватара пользователем: " + User.Identity.Name);
40+
return View();
41+
}
42+
43+
if (ModelState.IsValid)
3544
{
3645
model.MimeType = File.ContentType;
3746
model.Avatar = new byte[File.ContentLength];
47+
3848
File.InputStream.Read(model.Avatar, 0, File.ContentLength);
49+
model.AddPhoto();
50+
51+
logger.Info("Загрузка нового аватара пользователем: " + User.Identity.Name);
52+
return RedirectToAction("AboutMe", "Account");
3953
}
4054

41-
model.AddPhoto();
42-
return RedirectToAction("AboutMe", "Account");
55+
else
56+
{
57+
logger.Debug("Модель аватара невалидна у пользователя: " + User.Identity.Name);
58+
return View();
59+
}
4360
}
61+
4462
return View();
63+
64+
65+
4566

4667
}
4768

@@ -50,6 +71,7 @@ public FileContentResult GetImage(string name)
5071
if (name != null)
5172
{
5273
var info = AvatarModel.GetInfo(name);
74+
logger.Info("Загрузка аватара из базы для пользователя: " + User.Identity.Name);
5375
return File(info.Avatar, info.MimeType);
5476
}
5577
else

EPAM.MyBlog.UI.Web/Controllers/PostController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EPAM.MyBlog.UI.Web.Models;
2+
using log4net;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -9,6 +10,7 @@ namespace EPAM.MyBlog.UI.Web.Controllers
910
{
1011
public class PostController : Controller
1112
{
13+
private static ILog logger = LogManager.GetLogger(typeof(AdminController));
1214
//
1315
// GET: /Post/
1416

@@ -38,6 +40,7 @@ public ActionResult NewPost(PostModel model)
3840
//string Result;
3941
if (model.AddPost(User.Identity.Name.ToString()))
4042
{
43+
4144
return RedirectToAction("Index", "Post");
4245
}
4346
else
@@ -67,6 +70,7 @@ public ActionResult Posts(PostModel model, string action)
6770
if(action == "AddFav")
6871
{
6972
PostModel.AddFavorite(User.Identity.Name, model.Id);
73+
logger.Info("Добавлен пост с id: " + model.Id + "в избранное пользователя: " + User.Identity.Name);
7074
return RedirectToAction("Posts", new {Id = model.Id});
7175
}
7276
else
@@ -89,10 +93,12 @@ public ActionResult Edit(PostModel post)
8993
{
9094
if (post.EditPost())
9195
{
96+
logger.Info("Изменен пост id: " + post.Id + "у пользователя: " + User.Identity.Name);
9297
return RedirectToAction("Index", "Post");
9398
}
9499
else
95100
{
101+
logger.Error("Ошибка при изменении поста id: " + post.Id + "у пользователя: " + User.Identity.Name);
96102
return View();
97103
}
98104
}
@@ -115,10 +121,12 @@ public ActionResult Delete(Guid id, ConfirmModel model)
115121
{
116122
if (PostModel.Delete(id))
117123
{
124+
logger.Info("Удален пост id: " + id + "у пользователя: " + User.Identity.Name);
118125
return RedirectToAction("Index", "Post");
119126
}
120127
else
121128
{
129+
logger.Error("Ошибка при удалении поста id: " + id + "у пользователя: " + User.Identity.Name);
122130
return View();
123131
}
124132
}
@@ -139,10 +147,12 @@ public ActionResult DeleteFavorite(Guid id, ConfirmModel model)
139147
{
140148
if (PostModel.DeleteFavorite(User.Identity.Name, id))
141149
{
150+
logger.Info("Удален пост id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
142151
return RedirectToAction("Favorite", "Post");
143152
}
144153
else
145154
{
155+
logger.Error("Ошибка при удалении поста id: " + id + "из Избранного у пользователя: " + User.Identity.Name);
146156
return View();
147157
}
148158
}

EPAM.MyBlog.UI.Web/Logs/Debug/2015.01.17.log

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2015-01-20 14:37:28,883 [28] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ������� ����������� ������������� ������Admin2
2+
2015-01-20 14:38:05,449 [29] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ������� ����������� ������������� ������Admin2
3+
2015-01-20 16:12:02,026 [125] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2
4+
2015-01-20 17:25:12,440 [78] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
5+
2015-01-20 17:25:35,901 [77] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2

EPAM.MyBlog.UI.Web/Logs/Errors/2015.01.17.log

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2015-01-20 14:37:28,883 [28] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ������� ����������� ������������� ������Admin2
2+
2015-01-20 14:38:05,449 [29] INFO EPAM.MyBlog.UI.Web.Models.RegModel [(null)] - ������� ����������� ������������� ������Admin2
3+
2015-01-20 16:12:02,026 [125] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2
4+
2015-01-20 17:25:12,440 [78] INFO EPAM.MyBlog.UI.Web.Controllers.AccountController [(null)] - ������������ ����� �� �������: Admin2
5+
2015-01-20 17:25:35,901 [77] INFO EPAM.MyBlog.UI.Web.Models.LoginModel [(null)] - ���� � ������� ������������: Admin2

0 commit comments

Comments
 (0)